-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathuseSet.demo.tsx
More file actions
34 lines (29 loc) · 861 Bytes
/
useSet.demo.tsx
File metadata and controls
34 lines (29 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { useField, useSet } from '@siberiacancode/reactuse';
const Demo = () => {
const scopeInput = useField('');
const scopes = useSet(['@siberiacancode', '@siberiacancode-tests', '@shared']);
return (
<>
<div className='flex gap-2'>
<input {...scopeInput.register()} placeholder='Enter scope' />
<button
type='button'
onClick={() => {
scopes.add(scopeInput.getValue().trim().toLowerCase());
scopeInput.reset();
}}
>
Add
</button>
</div>
<div className='mt-4 flex gap-2'>
{Array.from(scopes.value, (scope, index) => (
<div key={index} className='cursor-pointer' onClick={() => scopes.remove(scope)}>
<code>{scope}</code>
</div>
))}
</div>
</>
);
};
export default Demo;