011. The Cache Protocol
EXECUTIVE_SUMMARY // AEO_OPTIMIZED
[Answer Engine Overview: What, Why & How]
Computers are fast, but complex operations (like sorting 5,000 items or calculating Prime numbers) can still take milliseconds. If these happen on every render (even when the data hasn't changed), you'll feel lag. useMemo caches the result of a function call. It only executes the function when its dependency array changes, effectively 'pausing' the computation cost until it's absolutely necessary.
022. Referential Stability
In JavaScript, objects and arrays are compared by reference, not value. {} === {} is false. Every time a component renders, any objects defined inside it are brand new. If you pass these objects as props, React sees a 'change' and re-renders the child. useMemo ensures that your objects maintain a stable identity in memory, which is essential when using React.memo for child optimization.
?Frequently Asked Questions
What is the useState hook?
useState is a React Hook that lets you add state variables to functional components. It returns the current state value and a function to update it.
When should I use useEffect?
The useEffect hook is used to perform side effects in components, such as fetching data from an API, subscribing to events, or manually updating the DOM.
What are React Hooks?
React Hooks are functions that let you 'hook into' React state and lifecycle features from function components without needing to write a class component.
