function usePrevious(value) { const ref = useRef(); useEffect(() => { ref.current = value; }, [value]); return ref.current; } // Utilisation function Counter() { const [count, setCount] = useState(0); const previousCount = usePrevious(count); return (
Actuel : {count}
Précédent : {previousCount}