Skip to content

Proposal to change state hook documentation #4572

Description

@matowang

The current documentation for setting state hooks is shown as:

<button onClick={() => setCount(count + 1)}>

However wouldn't it be much better to use the previous state?

<button onClick={() => setCount(prevCount => prevCount + 1)}>

This would be more consistent with the original setState documentation.

I have also personally had issues with states being handled incorrectly due to using the documented method of setting state with the rendered state.

Wouldn't this prevent a lot of logical errors people may face due to the documentation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions