Skip to content

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

Closed
@gmoniava

Description

@gmoniava

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions