with React state it was easy to set new value which was condition for render some input and then focus to that input with state callback.
handleToggleInput() {
const showInput = !this.state.showInput
this.setState({ showInput }, () => showInput && this.refs.input.focus())
}
render() {
if(this.state.showInput) {
<input ref="input" type="text />
}
}
Now when switching to Mobx it is not possible
@observable showInput = false;
handleToggleInput() {
this.showInput = !this.showInput
this.showInput && this.refs.input.focus()
}
render() {
if(this.showInput) {
<input ref="input" type="text />
}
}
This will fail, because React did not yet rerender component with input. Is there any way how wait and detect when rerender is done?