@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.06 kB
JavaScript
import { useReducer, useCallback, useMemo } from "react";
import { ComponentType, useSyncComponentState } from "../../context/context.js";
import { reducer } from "./reducer.js";
const useChartState = (id, options) => {
const [internalState, dispatch] = useReducer(reducer, {
selectedPoints: []
});
const changeSelection = useCallback((points) => {
dispatch({
type: "changeSelection",
points
});
}, []);
const optionsOnClearSelection = options.onClearSelection;
const clearSelection = useCallback(() => {
changeSelection([]);
optionsOnClearSelection == null ? void 0 : optionsOnClearSelection();
}, [changeSelection, optionsOnClearSelection]);
const state = useMemo(() => ({
id,
selectedPoints: internalState.selectedPoints,
changeSelection,
clearSelection,
componentType: ComponentType.Chart
}), [id, changeSelection, clearSelection, internalState.selectedPoints]);
useSyncComponentState(id, state);
return state;
};
export {
useChartState
};
//# sourceMappingURL=useChartState.js.map