/
githubmirror
/
ydb-embedded-ui
Обзор
Документация
Войти
/
githubmirror
/
ydb-embedded-ui
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/components/ComponentsProvider/ComponentsProvider.tsx
25 строк
817 B
Valerii Sidorenko
feat!: update to uikit 6 (#789)
10 апр 2024, 16:48
Не верифицирован
10 апр 2024, 16:48
1a3154d
Код
Авторство
О чём код?
import React from 'react'; import type {ComponentsRegistry} from './componentsRegistry'; const componentsStoreContext = React.createContext<ComponentsRegistry | undefined>(undefined); interface ComponentsProviderProps { registry: ComponentsRegistry; children: React.ReactNode; } export function ComponentsProvider({children, registry}: ComponentsProviderProps) { return ( <componentsStoreContext.Provider value={registry}> {children} </componentsStoreContext.Provider> ); } export function useComponent<T extends Parameters<ComponentsRegistry['get']>[0]>(id: T) { const store = React.useContext(componentsStoreContext); if (store === undefined) { throw new Error('useComponent must be used within ComponentsProvider'); } return store.get(id); }