import type { ScaleLinear } from 'd3-scale'; import { createContext, useContext } from 'react'; interface JGraphState { scaleY: ScaleLinear | null; height: number; maxValue: number; } const JGraphContext = createContext({ scaleY: null, height: 0, maxValue: 0, }); export const JGraphContextProvider = JGraphContext.Provider; export function useJGraph() { const jGraphState = useContext(JGraphContext); if (!jGraphState.scaleY) { throw new Error('scale cannot be null'); } return jGraphState; }