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