react-use-ref-state
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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>

}

Package Sidebar

Install

npm i react-use-ref-state

Weekly Downloads

2

Version

1.1.0

License

MIT

Unpacked Size

3.18 kB

Total Files

6

Last publish

Collaborators

  • shihao