react-native-popover-view: can't perform a react state updated on an unmounted component
@SteffeyDev I was trying to create a list of items along with tooltips,
While closing one of the tooltips, I got the warning can't perform a react state updated on an unmounted component.
It seems like the problem has nothing to do with my list example, the problem always appears in react native bare flow when popover is closed.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 18 (7 by maintainers)
Commits related to this issue
- Fix Github Issue - https://github.com/SteffeyDev/react-native-popover-view/issues/69 — committed to jeraldgan/react-native-popover-view by jeraldgan 2 years ago
There is a warning message only when opening and closing for the first time
Code
Log
@SteffeyDev just opened a PR to solve this issue.
I see this issue is closed @SteffeyDev, however this is definitely still happening for me, in 5.0.0 (RN 0.67.3 on iOS 15.4), when closing the popover. The source of the issue reported by React Native is calling
setStateinonCloseCompletefromAdaptivePopover.My conclusion is that the issue is because
AdaptivePopovercallsonCloseCompletesynchronously and sets state afterwards, it becomes possible foronCloseCompleteto causeAdaptivePopoverto unmount, and thensetStateis called on an unmounted component.I added some debugging to the relevant parts of the code to trace the execution of dismissing the popover:
In the log you can see that
π:AdaptivePopover:onCloseCompleteis emitted once before callingprops.onCloseCompleteand is still mounted at that point, however afteronCloseCompleteis called it has been unmounted right before callingsetState({showing: false}).Something that worked for me was to use the callback argument of
setStateto callonCloseComplete, changing this code to:Which makes sense because once the state has been updated to
showing: falsethen the close is truly complete, but Iβll admit to not fully exploring the implications.@mazenchamiβs PR included in 5.0.2. Going to close for now, will re-open if you still encounter the issue on 5.0.2
Thank you @jonathanj for the deep dive and solution.
Thanks for the research, Iβll look into this again next time Iβm working this project.