79198740

Date: 2024-11-18 05:04:55
Score: 1.5
Natty:
Report link

This happen because even though the state is updated, the pop up isn't, hence the state is stale. useRef wouldn't help because useRef will not trigger a re-render, its different than useState. Try making the handleOpenModal into a react component, and pass the counter as a prop. This way, everytime the state change, the modal will change as well.In the end the modal have to re-render everytime no matter what, but I think this approach is much better than the useEffect one, which can cause unnecessary re-render.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Single line (0.5):
  • Low reputation (1):
Posted by: Justin Hadinata