Update useSet docs

This commit is contained in:
suisous 2024-01-05 15:07:04 +09:00
parent 5aa843666b
commit d4e671dfca
2 changed files with 9 additions and 2 deletions

View File

@ -4,16 +4,22 @@ React state hook that tracks a [Set](https://developer.mozilla.org/en-US/docs/We
## Usage
What is the difference between the "clear()" method and the "reset()" method?
The "reset()" method returns the "Set" to the initial value passed during "useSet
The "clear()" method completely empties the "Set".
```jsx
import {useSet} from 'react-use';
const Demo = () => {
const [set, { add, has, remove, toggle, reset }] = useSet(new Set(['hello']));
const [set, { add, has, remove, toggle, reset, clear }] = useSet(new Set(['hello']));
return (
<div>
<button onClick={() => add(String(Date.now()))}>Add</button>
<button onClick={() => reset()}>Reset</button>
<button onClick={() => clear()}>Clear</button>
<button onClick={() => remove('hello')} disabled={!has('hello')}>
Remove 'hello'
</button>

View File

@ -4,12 +4,13 @@ import { useSet } from '../src';
import ShowDocs from './util/ShowDocs';
const Demo = () => {
const [set, { add, has, remove, reset, toggle }] = useSet(new Set(['hello']));
const [set, { add, has, remove, reset, clear, toggle }] = useSet(new Set(['hello']));
return (
<div>
<button onClick={() => add(String(Date.now()))}>Add</button>
<button onClick={() => reset()}>Reset</button>
<button onClick={() => clear()}>Clear</button>
<button onClick={() => remove('hello')} disabled={!has('hello')}>
Remove 'hello'
</button>