How do you avoid stale closures in useEffect?
Include the relevant values in the dependency array so the effect re-runs with the latest values. The hooks lint plugin helps get this right, and you can also use refs for values that should not trigger re-runs.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Advanced React Hooks Interview Questions With Answers
Because React tracks hooks by call order. Calling a hook inside a loop or condition changes the order between renders, breaking React's internal tracking and causing state to be assigned to the wrong hook, which causes subtle bugs.
useMemo memoizes a value; useCallback memoizes a function reference. Use useMemo for expensive computations and useCallback for stable function references passed to memoized children.
useState is for simple independent state. useReducer is for complex state with transitions, modeling state as a reducer that takes an action. Choose based on complexity and clarity.
Still have questions?
Browse all our FAQs or reach out to our support team
