react-use-ref-state
v1.1.0
Published
solve closure problems in useEffect
Downloads
3
Maintainers
Readme
use-ref-state
simple combination of useRef
and useState
to solve closure
problems in useEffect
.
Perfect surport in typescript.
Usage
import useRefState from 'react-use-ref-state';
const Demo = () => {
const [count, setCount] = useRefState(0);
useEffect(() => {
setInterval(() => {
console.log(count.current)
}, 1000)
}, [])
return <div onClick={() => setCount(count.current + 1)}>{count.current}</div>
}