use-prev-state
v0.1.0
Published
A simple hook that returns the previous state
Downloads
2
Readme
usePrevState
A simple hook that returns the previous state
Usage
import React, { useState } from 'react';
import usePrevState from 'use-prev-state';
const Demo = () => {
const [count, setCount] = useState(0);
const prevCount = usePrevState(count);
return (
<p>
<button onClick={() => setCount(count + 1)}>+</button>
<button onClick={() => setCount(count - 1)}>-</button>
<p>
Now: {count}, before: {prevCount}
</p>
</p>
);
};