Skip to content
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

[Mistake]: One of the examples in the docs is performing side effect in render? #6660

Closed
gmoniava opened this issue Feb 23, 2024 · 2 comments

Comments

@gmoniava
Copy link

gmoniava commented Feb 23, 2024

Summary

React docs warn us to not perform side effects during render (or even inside the body of hook like useMemo).
However, here: https://react.dev/reference/react-dom/hooks/useFormStatus#read-form-data-being-submitted,
it seems that is what is happening:

submittedUsername.current = data?.get('username');

Isn't writing to ref a side effect?

Actually there is single place in docs which allows to do side effect (change state) during render if it is wrapped inside certain condition,
however, even there they warn against DOM manipulation:

A condition like items !== prevItems is necessary to avoid loops. You may adjust state like this, but any other side effects (like changing the DOM or setting timeouts) should stay in event handlers or Effects to keep components pure.

Page

https://react.dev/reference/react-dom/hooks/useFormStatus#read-form-data-being-submitted

Details

No response

@pwbriggs
Copy link

Yes, you are correct.

Someone just spotted this error a few hours ago, and a fix is in progress at #6658.

@gmoniava
Copy link
Author

Thanks; I suppose I can close this then ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants