use-toggle@0.1.0
useState()
をtoggle用にwrapした
Custom Hook
code:script.js
import {useState, useCallback} from '../preact@10.5.13/hooks.js';
export function useToggle(value) {
const
flag, setFlag
= useState(value ?? false);
const toggle = useCallback(() => setFlag(flag => !flag), []);
return
flag, toggle
;
}