/
githubmirror
/
novu
Обзор
Документация
Войти
/
githubmirror
/
novu
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
next
apps/dashboard/src/utils/context.ts
20 строк
582 B
cursor[bot]
chore(root): remove 0 unused files and 9 unused exports (#10628)
09 апр 2026, 13:09
Не верифицирован
09 апр 2026, 13:09
a6a5540
Код
Авторство
О чём код?
import React from 'react'; function assertContextExists<T>(contextVal: unknown, msgOrCtx: string | React.Context<T>): asserts contextVal { if (!contextVal) { throw typeof msgOrCtx === 'string' ? new Error(msgOrCtx) : new Error(`${msgOrCtx.displayName} not found`); } } type UseCtxFn<T> = () => T; export const createContextHook = <CtxVal>(context: React.Context<CtxVal>): UseCtxFn<CtxVal> => { const useCtx = () => { const ctx = React.useContext(context); assertContextExists(ctx, `${context.displayName} not found`); return ctx; }; return useCtx; };