1.0.5 • Published 9 months ago

use-immer-ref v1.0.5

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

use-immer-ref

Manage state with immer, useRef more conveniently!

Install

$ npm install immer use-immer-ref
$ yarn add immer use-immer-ref

Usage

import { useImmerRef } from 'use-immer-ref';

const ExampleComponent = () => {
  const [state, setState, ref] = useImmerRef({
    count: 0,
  })
  return (
    <div>
      <button onClick={() => {
          setState(dr => {
            dr.count = 1;
          })
          console.log(ref.current.count) // console.log result => 1
          // ref.current will be changed to the latest value immediately
        }}>
        add count
      </button>
      <div>
        count is {state.count}
      </div>
    </div>
  );
};
1.0.5

9 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago