@airplane/views
Version:
A React library for building Airplane views. Views components are optimized in style and functionality to produce internal apps that are easy to build and maintain.
33 lines (32 loc) • 1.05 kB
JavaScript
import { useReducer, useMemo } from "react";
import { useStateSetters } from "../input/useStateSetters.js";
import { ComponentType, useSyncComponentState } from "../../context/context.js";
import { reducer } from "./reducer.js";
const useRadioGroupState = (id, options) => {
var _a, _b;
const initialState = {
value: ((_a = options == null ? void 0 : options.initialState) == null ? void 0 : _a.value) ?? void 0,
disabled: ((_b = options == null ? void 0 : options.initialState) == null ? void 0 : _b.disabled) ?? false
};
const [internalState, dispatch] = useReducer(reducer, {
...initialState,
showErrors: false,
errors: []
});
const stateSetters = useStateSetters(dispatch, initialState);
const state = useMemo(() => ({
...internalState,
...stateSetters,
id,
componentType: ComponentType.RadioGroup
}), [internalState, id, stateSetters]);
useSyncComponentState(id, state);
return {
state,
dispatch
};
};
export {
useRadioGroupState
};
//# sourceMappingURL=useRadioGroupState.js.map