rooks
Version:
Collection of awesome react hooks
26 lines (25 loc) • 957 B
TypeScript
type Add<T> = (...args: Parameters<Set<T>["add"]>) => void;
type Delete<T> = (...args: Parameters<Set<T>["delete"]>) => void;
export type UseSetStateControls<T> = {
add: Add<T>;
delete: Delete<T>;
clear: () => void;
};
export type UseSetStateReturnValue<T> = [Set<T>, UseSetStateControls<T>];
/**
* useSetState
* @description Manage the state of a Set in React.
* @param {Set<T>} initialSetValue The initial value of the set to manage.
* @returns {UseSetStateReturnValue<T>} The state of the Set and the controls.
* @see {@link https://rooks.vercel.app/docs/hooks/useSetState}
* @example
* import { useSetState } from "../hooks/useSetState";
* const [set, setControls] = useSetState(new Set());
* setControls.add(1); // {1}
* setControls.add(2); // {1, 2}
* setControls.delete(1); // {2}
* setControls.clear(); // {}
*
*/
declare function useSetState<T>(initialSetValue: Set<T>): UseSetStateReturnValue<T>;
export { useSetState };