Closed xelmido closed 6 years ago
It doesn't look like refluxjs supports a callback in setState. It is providing it's own setState method in between React's setState, needed because it has to loop through all of the components listening to the store. Since each component's setState is async, for this to work the way you'd expect it to with regular React it would have to wait for all the component callbacks, one for each component that listens to the store, not ideal if you really only care about a particular component.
I would do this by watching for the change in the component, for example:
componentDidUpdate(prevProps, PrevState){
if(prevState.something !== this.state.something) {
//do your resolve action here
alert('something has changed');
}
}
I already used the componentDidUpdate. It did the trick for my case.
Thanks for clearing it up I am closing this for now!
In some scenarios i need to use a callback of the setState. But, it doesn't trigger the callback in a store. Am i do something wrong? Or is it a bug in the Reflux.store. E.g:
onSetSomething(id, resolve) { this.setState({ something: Id } () => { resolve(); }); }