import React, { useContext, useMemo } from "react"; import { typedMemo } from "../utils"; type CellContextValue = { isActive: boolean; }; const CellContext = React.createContext( undefined ); type Props = { isActive: boolean; children: React.ReactNode; }; export function CellProvider({ isActive, children }: Props) { const value = useMemo( () => ({ isActive, }), [isActive] ); return {children}; } export default typedMemo(CellProvider); export function useIsActive() { const value = useContext(CellContext); if (!value) { throw new Error("useIsActive must be called from within CellProvider!"); } return value.isActive; }