Redux: unsubscribe during dispatching throws warning in child component

Created on 16 May 2016  路  1Comment  路  Source: reduxjs/redux

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?

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.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

parallelthought picture parallelthought  路  3Comments

benoneal picture benoneal  路  3Comments

ms88privat picture ms88privat  路  3Comments

CellOcean picture CellOcean  路  3Comments

rui-ktei picture rui-ktei  路  3Comments