mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
Update useSet docs
This commit is contained in:
parent
5aa843666b
commit
d4e671dfca
@ -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>
|
||||
|
||||
@ -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>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user