Skip to content

Commit e8c4078

Browse files
committed
Refactor single chart context exports
1 parent 0823548 commit e8c4078

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

projects/js-packages/charts/src/components/single-chart-context/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
export {
2-
SingleChartContext,
3-
ChartInstanceContext,
4-
useChartInstanceContext,
5-
useSingleChartContext,
6-
} from './single-chart-context';
1+
export { SingleChartContext, ChartInstanceContext } from './single-chart-context';
2+
export { useChartInstanceContext, useSingleChartContext } from './use-single-chart-context';
73
export type {
84
ChartInstanceContextValue,
95
ChartInstanceRef,

projects/js-packages/charts/src/components/single-chart-context/single-chart-context.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createContext, useContext } from 'react';
1+
import { createContext } from 'react';
22

33
export interface ChartInstanceRef {
44
getScales: () => { xScale: unknown; yScale: unknown } | null;
@@ -19,16 +19,7 @@ export interface ChartInstanceContextValue {
1919

2020
export const ChartInstanceContext = createContext< ChartInstanceContextValue | null >( null );
2121

22-
export const useChartInstanceContext = (): ChartInstanceContextValue => {
23-
const context = useContext( ChartInstanceContext );
24-
if ( ! context ) {
25-
throw new Error( 'useChartInstanceContext must be used within a Chart component' );
26-
}
27-
return context;
28-
};
29-
3022
// Backward compatibility exports
3123
export const SingleChartContext = ChartInstanceContext;
3224
export type SingleChartContextValue = ChartInstanceContextValue;
3325
export type SingleChartRef = ChartInstanceRef;
34-
export const useSingleChartContext = useChartInstanceContext;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { useContext } from 'react';
2+
import { ChartInstanceContextValue, ChartInstanceContext } from './single-chart-context';
3+
4+
export const useChartInstanceContext = (): ChartInstanceContextValue => {
5+
const context = useContext( ChartInstanceContext );
6+
if ( ! context ) {
7+
throw new Error( 'useChartInstanceContext must be used within a Chart component' );
8+
}
9+
return context;
10+
};
11+
12+
export const useSingleChartContext = useChartInstanceContext;

0 commit comments

Comments
 (0)