-1

I was wondering if the mobx cycle is triggered on observable change only in stores outside of react components in HOClass operation because there is a top level Provider to mobx stores which is triggering a react component re-render.

  ReactDOM.render(<Provider { ...stores } >
              <Routes />
              </Provider>, 

But does that mean I can't add observables directly to react components? if so that is a bit unfortunate.

@observer
export default class Profile extends React.Component {
  @observable name;
  componentWillMount() {
    this.name = this.props.name;
  }
  txtChange = (e) => {
    this.name = e.target.value;
  }
  render() {
    return (
      <div>
      <input type="text" onChange={this.txtChange} value={this.name}/>
      </div>
    )
  }

for some reason on my app I cannot update the observable name. On some apps using mobx however I can. Why am I unable to change the value of this and trigger a react state update if the observable is attached to the React.Component itself?

Here I have forms updating in controlled observable fashion but when Provider 'ing my router on my current project under this setup no react rerender is triggered.

https://codepen.io/cheapsteak/pen/wzdvzQ

Help anyone?

mibbit
  • 4,997
  • 3
  • 26
  • 34

1 Answers1

0

There (was) a typo: the function is called txtChange but the component references this.txthange instead. Either way, here's a fixed working example: https://codepen.io/justnobody/pen/RxJmmY?editors=1010

kingdaro
  • 11,528
  • 3
  • 34
  • 38
  • in codepen it works, in my local project howevertextinput does not update. I will provide a github repo in a few minutes. – mibbit Jan 13 '18 at 23:37