Warning: setState(...): Can only update a mounted or mounting component
I have a parent and child component. They both subscribe to my redux store. Upon store's state change, the parent handler is called first and changes its state to hide the child component (e.g. render() is called). Because the child is not rendered, the child's componentWillUnmount() method is then called and I unsubscribe() from the redux store in that method.
After that, the redux dispatching continues and the child handler method still gets called and this warning is the result because I'm updating the child's state in that handler.
If unsubscribe can't work between dispatching, then I don't understand how to do basic UI state changes like hiding or hiding components. Could I be doing something wrong?
First, usage questions should really go on Stack Overflow - filing issues should be reserved for actual bugs with Redux.
Second, it sounds like you're trying to manage store subscriptions manually. Don't do that - use the official React Redux bindings, which take care of all the store subscription process for you, and also give you some nice performance optimizations.
Try switching your components to use React Redux's connect() function, and I would just about guarantee your problem will go away.
Most helpful comment
First, usage questions should really go on Stack Overflow - filing issues should be reserved for actual bugs with Redux.
Second, it sounds like you're trying to manage store subscriptions manually. Don't do that - use the official React Redux bindings, which take care of all the store subscription process for you, and also give you some nice performance optimizations.
Try switching your components to use React Redux's
connect()function, and I would just about guarantee your problem will go away.