-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't perform a React state update on an unmounted component. When switching view with react route #59
Comments
Hi @hostlund , Thanks for bringing this to my attention. I've looked into it, and reproduced what is happening in a Codesandbox here: https://codesandbox.io/s/react-and-pullstate-state-update-leak-cxbky The strange thing is, in my dev environment I'm not getting these errors at all. Only in the sandbox. Okay, I just figured out what the difference was between the environments. Its because of I don't really know what to do, because as far as I can see the pullstate code is doing everything expected for React components when it comes to mounting and unmounting, and I've never got those warnings about Pullstate popping without StrictMode turned on (but I still get warnings where there obviously are violations of the rule). You can see the relevant code here: seEffect(() => {
updateRef.current.shouldUpdate = true;
return () => {
updateRef.current.shouldUpdate = false;
store._removeUpdateListener(updateRef.current.onStoreUpdate!);
};
}, []); That if (updateRef.current.shouldUpdate) {
updateRef.current.currentSubState = nextSubState;
setUpdateTrigger((val) => val + 1);
} It is something to look into in more depth, so I'll keep an eye on it, but I have my suspicions that its a false non-issue caused by StrictMode that we can probably safely ignore it. I've looked a bit into it now and noticed this issue, which could be a clue: facebook/react#17193 |
Thanks for the clarification @lostpebble Disabling strict mode was one thing I didn't try. It seems to work without any errors if I remove strict mode so I guess it due to that React issue. I will close this issue now. |
I'm trying to use PullState in an app with a few react routes and get the error " Can't perform a React state update on an unmounted component." when I use some kind of callback to update the store. Small example inlined. Switch view and press the Test 1, 2 or 3 link. In the console you get (Can't perform a React state update on an unmounted component.) Seems to be "setUpdateTrigger((val) => val + 1);" in useStoreState that triggers the warning. Are we initializing the store the wrong way or should this work?
store.js
Quick example, based on create react app and added react router
The text was updated successfully, but these errors were encountered: