@utilityjs/use-previous-value
v1.0.1
Published
A React hook that returns a value from the previous render.
Downloads
7
Maintainers
Readme
A React hook that returns a value from the previous render.
npm i @utilityjs/use-previous-value | yarn add @utilityjs/use-previous-value
Usage
import usePreviousValue from "@utilityjs/use-previous-value";
import * as React from "react";
const useHook = () => {
const [open, setOpen] = React.useState(false);
const prevOpen = usePreviousValue(open);
React.useEffect(() => {
if (open !== prevOpen) {
console.log("The state has been changed!");
}
}, [open])
};
API
usePreviousValue(value)
declare const usePreviousValue: <T>(value: T) => T | undefined;
value
The value on the current render.