# All files / src SsrProvider.tsx

100% Statements 42/42
100% Branches 3/3
100% Functions 2/2
100% Lines 42/42

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
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    431x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    4935x
    4935x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    296x
    296x
    296x
    176x
    296x
    296x
    296x
     "use client";
    import {
      createContext,
      useContext,
      useEffect,
      useState,
      type ReactElement,
      type ReactNode,
    } from "react";

    const context = createContext(false);
    const { Provider } = context;
    context.displayName = "Ssr";

    /**
     * @remarks \@since 6.0.0
     */
    export function useSsr(): boolean {
      return useContext(context);
    }

    /**
     * @remarks \@since 6.0.0
     */
    export interface SsrProviderProps {
      ssr?: boolean;
      children: ReactNode;
    }

    /**
     * **Client Component**
     *
     * @remarks \@since 6.0.0
     */
    export function SsrProvider(props: SsrProviderProps): ReactElement {
      const { ssr = false, children } = props;
      const [isSsr, setSsr] = useState(ssr);
      useEffect(() => {
        setSsr(false);
      }, []);
      return <Provider value={isSsr}>{children}</Provider>;
    }