3

I tried to update the state when store data changed. I subscribe on componentDidMount and unsubscribe on componentWillUnmount as below:

componentDidMount() {   
const { store } = this.context
this.unsubscribe = store.subscribe(() => {      
this.setState({ 
skillsValue: store.getState().admin.userProfile.seeker.skillsValue || [],
...
componentWillUnmount()
{
this.unsubscribe
}

However, I got this warning.

Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a no-op. Please check the code for the xxxx component.

Steve
  • 31
  • 2
  • they're all using `react-redux` now. it may cleanup these things for you. maybe not many people care about this problem but i still expect a good solution for it. not only react but also angular has encounted with the [same problem](http://stackoverflow.com/questions/38008334/angular2-rxjs-when-should-i-unsubscribe-from-subscription)! – Clite Tailor Apr 23 '17 at 17:45

0 Answers0