/** * useContext Hook for Woby Framework * * This hook provides access to context values within functional components. * It works with contexts created by createContext and supports both default and undefined values. * * @module useContext */ import type { Context, ContextWithDefault } from '../types'; /** * Accesses the current value of a context * * This hook returns the current context value for the specified context. * It must be called within a functional component or a custom hook. * * The hook will first try to get the context value from the nearest Provider component * above it in the tree. If there is no Provider above it, it will return the defaultValue * if one was provided to createContext, otherwise it returns undefined. * * @template T - The type of the context value * @param Context - The context object created by createContext * @returns The current context value * * @example * ```tsx * // Create a context * const ThemeContext = createContext('light') * * // Use the context in a component * const ThemedButton = () => { * const theme = useContext(ThemeContext) * return * } * * // Provide a value for the context * const App = () => ( * * * * ) * ``` * * @example * ```tsx * // Context with undefined default * const UserContext = createContext(undefined) * * const UserProfile = () => { * const user = useContext(UserContext) * if (!user) return
Please log in
* return
Welcome, {user.name}!
* } * ``` */ export declare function useContext(Context: ContextWithDefault): T; export declare function useContext(Context: Context): T | undefined; //# sourceMappingURL=use_context.d.ts.map