@mui/x-charts
Version:
The community edition of MUI X Charts components.
32 lines • 765 B
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import * as React from 'react';
import { createChartDefaultId } from "./useChartId.utils.js";
export const useChartId = ({
params,
store
}) => {
React.useEffect(() => {
store.update(prevState => {
if (params.id === undefined || params.id === prevState.id.providedChartId && prevState.id.chartId !== undefined) {
return prevState;
}
return _extends({}, prevState, {
id: _extends({}, prevState.id, {
chartId: params.id ?? createChartDefaultId()
})
});
});
}, [store, params.id]);
return {};
};
useChartId.params = {
id: true
};
useChartId.getInitialState = ({
id
}) => ({
id: {
chartId: id,
providedChartId: id
}
});