I am fetching data in componentDidMount and updating the state and the famous warning is appearing:
Can\'t perform a React state update on an unmounted co
Just create flag in state: isMounted: false. In componentDidMount set state isMounted = true and in componentWillUnmount: set state isMounted = false.
isMounted: false
isMounted = true
isMounted = false
And in the async function that need use setState function, wrap them by condition if(this.state.isMounted) { ....setState action }
if(this.state.isMounted) { ....setState action }