UNPKG

@keycloakify/keycloak-account-ui

Version:

<p align="center"> <img src="https://github.com/user-attachments/assets/e31c4910-7205-441c-9a35-e134b806b3a8"> </p> <p align="center"> <i>Repackaged Keycloak Account UI</i> <br> <br> <a href="https://github.com/keycloakify/keycloak-a

25 lines (21 loc) 818 B
import type { Context } from "react"; import { useContext } from "react"; import { isDefined } from "@keycloakify/keycloak-account-ui/ui-shared/utils/isDefined"; /** * Passes the call to `useContext` and throw an exception if the resolved value is either `null` or `undefined`. * Can be used for contexts that are required and should always have a non nullable value. * * @param context The context to pass to `useContext` * @returns */ export function useRequiredContext<T>(context: Context<T>): NonNullable<T> { const resolved = useContext(context); if (isDefined(resolved)) { return resolved; } throw new Error( `No provider found for ${ context.displayName ? `the '${context.displayName}'` : "an unknown" } context, make sure it is included in your component hierarchy.`, ); }