usePrevious
Get the previous render value.
Usage
usePrevious
let you get the previous render value. At first render, the value is undefined
.
import { useEffect } from "react";
import { usePrevious } from "swash/utils/usePrevious";
function Example({ value }) {
const previousValue = usePrevious(value);
useEffect(() => {
// Value changes from `true` to `false`
if (previousValue === true && value === false) {
// ...
}
}, [value, previousValue]);
}