UNPKG

@mantine/hooks

Version:

A collection of 50+ hooks for state and UI management

15 lines (14 loc) 515 B
"use client"; import { useReducer } from "react"; //#region packages/@mantine/hooks/src/use-toggle/use-toggle.ts function useToggle(options = [false, true]) { const [[option], toggle] = useReducer((state, action) => { const value = action instanceof Function ? action(state[0]) : action; const index = Math.abs(state.indexOf(value)); return state.slice(index).concat(state.slice(0, index)); }, options); return [option, toggle]; } //#endregion export { useToggle }; //# sourceMappingURL=use-toggle.mjs.map