-
Notifications
You must be signed in to change notification settings - Fork 55
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
Using container on update hook causes React 16 errors to be printed #223
Comments
Is it duplicated? |
This isn't really a "change in behaviour caused by React 17 to 18", but it is a bug in React 16 where using the setState API in onUpdate will always trigger an error to be logged. This is a problem because developers will be confused by the warnings being logged and not know that they are coming from React Sweet State. This is still an issue with certain options after #221. I suggest the |
Marked as duplicated because it has the same root cause: the conversion to functional component. By going back to class and using |
While we work on #221 , a workaround is to set
which is what we use across some products in production |
When using container
onUpdate
hooks and setting state in them,react-sweet-state
may call set state during render when the container props change.This causes a warning on react 16 "Warning: Cannot update a component (
Child
) while rendering a different component".The problem is caused by this section running on render:
The following example reproduces the bug:
A sandbox reproduction is on - https://codesandbox.io/p/sandbox/cranky-dew-lvdhwv?file=%2Fsrc%2FApp.jsx%3A1%2C1-42%2C1
The text was updated successfully, but these errors were encountered: