Files
cnapp/src/hooks.js
T

15 lines
375 B
JavaScript

/* eslint-disable import/prefer-default-export */
import { useRef, useEffect } from 'react';
export function usePrevious(value) {
const ref = useRef();
// Store current value in ref
useEffect(() => {
ref.current = value;
}, [value]); // Only re-run if value changes
// Return previous value (happens before update in useEffect above)
return ref.current;
}