UNPKG

@appbuckets/react-ui

Version:
32 lines (29 loc) 742 B
import { __read } from 'tslib'; import * as React from 'react'; /** * Use this hook to get automatically the checkbox value * and the handler function to attach to checkbox. * Additionally function to force change will be returned * * @param initialValue */ function useCheckboxValue(initialValue) { // ---- // Internal State // ---- var _a = __read(React.useState(!!initialValue), 2), checked = _a[0], setChecked = _a[1]; // ---- // Handler // ---- var handleCheckboxChange = React.useCallback(function (e, props) { /** Update the value */ setChecked(!!props.checked); }, []); // ---- // Hook Return // ---- return [checked, handleCheckboxChange, setChecked]; } export { useCheckboxValue };