import type { ScaleLinear } from "d3-scale"; import React, { useContext, createContext, type PropsWithChildren, } from "react"; interface CartesianChartContext { xScale: ScaleLinear; yScale: ScaleLinear; } const CartesianChartContext = createContext( undefined, ); interface CartesianChartProviderProps { xScale: ScaleLinear; yScale: ScaleLinear; } export const CartesianChartProvider = ( props: PropsWithChildren, ) => { const { children, xScale, yScale } = props; return ( {children} ); }; export const useCartesianChartContext = () => { const context = useContext(CartesianChartContext); if (context === undefined) { throw new Error( "useCartesianChartContext must be used within a CartesianChartProvider", ); } return context; };