simple-react-ui-kits
Version:
A lightweight, customizable React UI component library built with TypeScript and Tailwind CSS
16 lines (13 loc) • 507 B
text/typescript
import { useState, useCallback } from 'react';
/**
* Custom hook for toggle functionality
* @param initialValue - Initial toggle state
* @returns [state, toggle, setState] - Current state, toggle function, and setter
*/
export function useToggle(initialValue = false): [boolean, () => void, (value: boolean) => void] {
const [state, setState] = useState(initialValue);
const toggle = useCallback(() => {
setState(prev => !prev);
}, []);
return [state, toggle, setState];
}