Lesson 9
Ref Callback Cleanup
ref Cleanup Functions
The Shift: When using a "Callback Ref" (a function passed to ref instead of a useRef object), you couldn't easily clean up side effects when the element was removed. React 19 allows you to return a cleanup function, exactly like useEffect.
👀 Preview
When the element is removed, the cleanup function automatically runs, disconnecting the observer.
📚 Explanation
Ref callbacks in React 19 can return a cleanup function, similar to `useEffect`. This cleanup function is called when the element is removed from the DOM, making it easy to clean up observers, event listeners, or other side effects.
App.tsx
How well did you remember this?