_buildState called on unmounted component
omatrot opened this issue · 3 comments
I have the following issue:
I'm using the navigator in conjonction with a side menu and a Resub store.
I have a root component that is the orchestrator for the menu and the navigator component.
I have several screens.
The root component and the various screens components all extends ComponentBase, thus implements _buildState().
When the navigator is first mounted, I reset the stack to a welcome screen.
Basically, here is the timeline of events:
*App Start
buidState() is called in the following order for the following components:
Root -> Menu -> Welcome
Now let's say that the user chooses a menu item that directs to a new screen not extending ComponentBase. I do not push the new route on the navigator stack but replace the current top route.
I have the following events that comes in:
NewScreen::ComponentDidMount
Welcome::ComponentWillUnmount
So far so good. In this new screen I click a button that calls the resub store to set a value.
- This has the effect of calling _buildState on Root/Menu and Welcome components
The problem here is that the Welcome component has been unmounted. This triggers the warning : 'Can't perform a React state update on an unmounted component...'
Am i doing something wrong or is this a bug?
The symptoms your describing sound a lot like you're overriding some react life cycle methods (componentWillUnmount, componentDidMount, ect) without calling super. If you do this, you must call super in your implementation. See here for a reference: https://github.com/Microsoft/ReSub/blob/master/README.md#subclassing
You're absolutely right. My fault.
But calling super seems to be forbidden:
error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors.