@appbuckets/react-ui
Version:
Just Another React UI Framework
64 lines (57 loc) • 1.47 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var tslib = require('tslib');
var React = require('react');
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(
n,
k,
d.get
? d
: {
enumerable: true,
get: function () {
return e[k];
},
}
);
}
});
}
n['default'] = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/ _interopNamespace(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 = tslib.__read(React__namespace.useState(initialValue), 2),
radioValue = _a[0],
setRadioValue = _a[1];
// ----
// Handler
// ----
var handleRadioChange = React__namespace.useCallback(function (e, props) {
/** Set new value */
setRadioValue(props.value);
}, []);
// ----
// Hook Return
// ----
return [radioValue, handleRadioChange, setRadioValue];
}
exports.useRadioValue = useRadioValue;