# All files / src/context GrackleContext.ts

20% Statements 1/5
0% Branches 0/1
0% Functions 0/1
20% Lines 1/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31

    5x

     /**
     * Shared GrackleContext definition used by both the real GrackleProvider (in @grackle-ai/web)
     * and MockGrackleProvider (in this package). Only the raw context + consumer hook live here;
     * the actual provider with gRPC wiring lives in @grackle-ai/web.
     *
     * @module
     */

    import React, { createContext, useContext } from "react";
    import type { UseGrackleSocketResult } from "./GrackleContextTypes.js";

    /** Re-export the socket result type so consumers can reference it. */
    export type { UseGrackleSocketResult };

    /** Alias for the context value type. */
    export type GrackleContextType = UseGrackleSocketResult;

    /** The raw React context for Grackle state. */
    export const GrackleContext: React.Context<GrackleContextType | undefined> = createContext<
      GrackleContextType | undefined
    >(undefined);

    /** Consumes the Grackle context; must be called within a GrackleProvider or MockGrackleProvider. */
    export function useGrackle(): GrackleContextType {
      const ctx = useContext(GrackleContext);
      Iif (!ctx) {
        throw new Error("useGrackle must be used within GrackleProvider");
      }
      return ctx;
    }