Skip to content

setState in useEffect causes rerender #3

@gradyzhu

Description

@gradyzhu

current behavior:

  • render is called when updater callback is passed to setState in useEffect hook.
  • component renders twice in total

expectation:

  • component is rendered once in total
useEffect(() => {
  setState((state) => {
    const newState = state + 1;
    return newState;
  });
}, [])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions