UNPKG

@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.

35 lines (34 loc) 1.1 kB
import { useReducer, useMemo } from "react"; import { ComponentType, useSyncComponentState } from "../../context/context.js"; import { reducer } from "./reducer.js"; import { useStateSetters } from "../input/useStateSetters.js"; const useMultiInputState = (id, options) => { var _a, _b; const initialState = { id, componentType: ComponentType.MultiInput, value: ((_a = options == null ? void 0 : options.initialState) == null ? void 0 : _a.value) ?? [], 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.MultiInput }), [internalState, stateSetters, id]); useSyncComponentState(id, state); return { state, dispatch }; }; export { useMultiInputState }; //# sourceMappingURL=useMultiInputState.js.map