mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
24 lines
387 B
Markdown
24 lines
387 B
Markdown
# `useGetSetState`
|
|
|
|
A mix of `useGetSet` and `useGetSetState`.
|
|
|
|
|
|
## Usage
|
|
|
|
```jsx
|
|
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>
|
|
);
|
|
};
|
|
```
|