UNPKG

@appbuckets/react-ui

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