@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) • 889 B
JavaScript
import { useReducer, useCallback, useMemo } from "react";
import { ComponentType, useSyncComponentState } from "../../context/context.js";
import { reducer } from "./reducer.js";
const useDialogState = (id, options) => {
var _a;
const [internalState, dispatch] = useReducer(reducer, {
opened: ((_a = options == null ? void 0 : options.initialState) == null ? void 0 : _a.opened) ?? false
});
const open = useCallback(() => {
dispatch({
type: "open"
});
}, []);
const close = useCallback(() => {
dispatch({
type: "close"
});
}, []);
const state = useMemo(() => ({
id,
open,
close,
opened: internalState.opened,
componentType: ComponentType.Dialog
}), [id, internalState.opened, open, close]);
useSyncComponentState(id, state);
return state;
};
export {
useDialogState
};
//# sourceMappingURL=useDialogState.js.map