Build a usePrevious Hook
Write the code, see it run, pass the checks.
The problem
- easy
- Code
Write a custom hook and export it by name: usePrevious(value) returns the value it was given on the previous render of the same component, and undefined on the first render. It works for any kind of value (numbers, strings, objects), and each component that calls it keeps its own. The default export App shows a count next to its previous value in the preview; the checks test usePrevious itself.
Your code must pass
- Returns undefined on the first render
- Returns the value from the render before
- Each component keeps its own previous value