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
Bug: creating the initial state #26277
Comments
this is an example of passing the initializer function to set state from the react docts beta
I am not sure why createCards() function is not initializing properly |
Hi @Dave-Patsy
I've did it an the problem is gone |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you! |
React version: "18.2.0"
The bug is failure of state initialization with a function, and not being consistent with the client and server. the fix is to use useEffect with empty dependency to initialize the state when the component is mounted on client.
I undertstand that useEffect is for synchronization, so it makes sense to initialize all states when component mounts.
However, I don't understand why it's not initializing the state with the function and then sending it to the client.
memory.tsx
memoryCard.tsx
memoryData.ts
React version: "18.2.0"
Steps To Reproduce
Link to code example: https://github.com/Dave-Patsy/stateInitializeError
The current behavior
The server and client props are not concurrent
The expected behavior
When I initialize a useState with a function on a client component I expect the server to use the function to initialize the state once, and then then the component to the client, so they are to be concurrent.
The fix is to use useEffect to initialize the state after component is mounted
The text was updated successfully, but these errors were encountered: