@appbuckets/react-ui
Version:
Just Another React UI Framework
32 lines (29 loc) • 742 B
JavaScript
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 };