const MyComponent = () => {
const [state, setState] = useState(initialState);
const prevState = useRef();
// Store the previous state
useEffect(() => {
prevState.current = state;
}, [state]);
// Perform diffing with useMemo
const diff = useMemo(() => {
return deepDiff(prevState.current, state);
}, [state]);
// ... rest of the component
};
view raw MyComponent.jsx hosted with ❤ by GitHub