keycloak-scim/apps/admin-ui/src/utils/createNamedContext.ts

12 lines
368 B
TypeScript
Raw Normal View History

2022-08-03 13:15:04 +00:00
import type { Context } from "react";
import { createContext } from "react";
export type NamedContext<T> = Context<T> &
Required<Pick<Context<T>, "displayName">>;
export function createNamedContext<T>(displayName: string, defaultValue: T) {
const context = createContext(defaultValue);
context.displayName = displayName;
return context as NamedContext<T>;
}