usePrevious()
↔ Custom Hook to get previous value of props
or state
export default function usePrevious(value) {
const ref = useRef()
useEffect(() => {
ref.current = value
}, [value])
return ref.current
}
function App() {
const [count, setCount] = useState(0)
const prevCount = usePrevious(count)
return (// generic counter app)
}