UseBooleanExample
src/prod/booleans/useBoolean.ts
import React from 'react'; export const useBoolean = (intialState = false) => { const [x, setX] = React.useState(intialState); const setXSafe = (x: boolean) => { if (x === true) { setX(true); } else if (x === false) { setX(false); } }; const toggleX = () => setX((x: boolean) => !x); return [x, setXSafe, toggleX]; };
dist/prod/booleans/useBoolean.js
import React from 'react'; export const useBoolean = (intialState = false) => { const [x, setX] = React.useState(intialState); const setXSafe = (x) => { if (x === true) { setX(true); } else if (x === false) { setX(false); } }; const toggleX = () => setX((x) => !x); return [x, setXSafe, toggleX]; };
src/prod/booleans/useBoolean.ts
import React from 'react'; export const useBoolean = (intialState = false) => { const [x, setX] = React.useState(intialState); const setXSafe = (x: boolean) => { if (x === true) { setX(true); } else if (x === false) { setX(false); } }; const toggleX = () => setX((x: boolean) => !x); return [x, setXSafe, toggleX]; };