usePrevious
If you want to access the previous props or state in functional components, you can use the usePrevious hook. This hook would work for props, state, or any other calculated value.
import {usePrevious} from 'react-use-custom-hooks';
Usage example​
const [value, setvalue] = useState(initialState);
const previousValue = usePrevious(value);
Playground​
Live Editor
Result
Loading...
API​
function usePrevious<T>(value: T): T | undefined;
Params​
| Property | Description | Type | Default |
|---|---|---|---|
| value | The state/prop value that previous value required | any | - |