Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 388 Bytes

useGetSetState.md

File metadata and controls

23 lines (17 loc) · 388 Bytes

useGetSetState

A mix of useGetSet and useGetSetState.

Usage

import {useGetSetState} from 'react-use';

const Demo = () => {
  const [get, setState] = useGetSetState({cnt: 0});
  const onClick = () => {
    setTimeout(() => {
      setState({cnt: get().cnt + 1})
    }, 1_000);
  };

  return (
    <button onClick={onClick}>Clicked: {get().cnt}</button>
  );
};