Implement a useSet hook that manages a JavaScript Set of items with additional utility methods.
It is more convenient to use useSet instead of plain useState because with useState, you would always have to create a new Set, mutate it, then set state to use the new set, which can be quite cumbersome.
The hook should work generically with items of any type.
export default function Component() {const { set, add, remove, toggle, reset, clear } = useSet(new Set(['hello']));return (<div><button onClick={() => add(Date.now().toString())}>Add</button><button onClick={() => remove('hello')} disabled={!set.has('hello')}>Remove 'hello'</button><button onClick={() => toggle('hello')}>Toggle hello</button><button onClick={reset}>Reset</button><button onClick={clear}>Clear</button><pre>{JSON.stringify(Array.from(set), null, 2)}</pre></div>);}
initialState: The initial Set of itemsThe hook returns an object with the following properties:
set: The current set of itemsadd: (item) => void: A function that adds item to the setremove: (item) => void: A function that removes item from the settoggle: (item) => void: A function that toggles the presence of item in the setreset: () => void: A function that resets the set to initialStateclear: () => void: A function that removes all items from the setSet instance so React can observe the state change.set object directly.reset() restores the supplied initialState; clear() replaces the state with an empty set.add, remove, and toggle should derive their next state from the latest previous set.console.log() statements will appear here.