UNPKG

@assistant-ui/react

Version:

TypeScript/React library for AI Chat

19 lines 690 B
"use client"; import { useContext } from "react"; /** * Creates a context hook with optional support. * @param context - The React context to consume. * @param providerName - The name of the provider for error messages. * @returns A hook function that provides the context value. */ export function createContextHook(context, providerName) { function useContextHook(options) { const contextValue = useContext(context); if (!options?.optional && !contextValue) { throw new Error(`This component must be used within ${providerName}.`); } return contextValue; } return useContextHook; } //# sourceMappingURL=createContextHook.js.map