1.1.0 • Published 11 months ago

react-use-ref-state v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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>

}