79150405

Date: 2024-11-02 10:06:57
Score: 0.5
Natty:
Report link

You can find answer here: https://github.com/facebook/react/issues/20817 or here: https://legacy.reactjs.org/docs/hooks-reference.html#bailing-out-of-a-state-update

If you update a State Hook to the same value as the current state, React will bail out without rendering the children or firing effects. (React uses the Object.is comparison algorithm.)

Note that React may still need to render that specific component again before bailing out. That shouldn’t be a concern because React won’t unnecessarily go “deeper” into the tree. If you’re doing expensive calculations while rendering, you can optimize them with useMemo.

That's why your component will render 1 more time with the same result

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Dmitriy Glazkov