usePrevious
#
DescriptionGet the previous value of a state value.
#
Usageimport { useState } from 'react';import { usePrevious } from '@springtree/eva-suite-react-hooks';
const Example = () => { const [count, setCount] = useState<number>(0); const previousCount = usePrevious(count);
return ( <> <div> {`Current count: ${count}`} </div> <div> {`Previous count: ${previousCount}`} </div> <button onClick={() => setCount((state) => state - 1)}>Decrease</button> <button onClick={() => setCount((state) => state + 1)}>Increase</button> </> )}
export default Example;