usePrevious
Keep track of the previous render's state.
Previous: undefined
Current: 0
Usage Example
1import { useState } from 'react';
2import { usePrevious } from '@danixsoft/hooks';
3
4function Counter() {
5 const [count, setCount] = useState(0);
6 const prevCount = usePrevious(count);
7
8 return (
9 <div>
10 <p>Now: {count}, Before: {prevCount}</p>
11 <button onClick={() => setCount(c => c + 1)}>Increment</button>
12 </div>
13 );
14}