react-code-dataset / react-use /docs /useGetSetState.md
Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
|
raw
history blame
387 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})
    }, 1000);
  };

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