/
githubmirror
/
ydb-embedded-ui
Обзор
Документация
Войти
/
githubmirror
/
ydb-embedded-ui
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/containers/Tenant/ObjectSummary/UpdateTreeContext.tsx
41 строка
1 KB
Hellen
fix: route schema object links in nav v2 (#4094)
07 июл 2026, 18:51
Не верифицирован
07 июл 2026, 18:51
ade3ecd
Код
Авторство
О чём код?
import React from 'react'; const TreeKeyContext = React.createContext<string | undefined>(undefined); const TreeKeyDispatchContext = React.createContext<React.Dispatch<string> | undefined>(undefined); interface TreeKeyProviderProps { children: React.ReactNode; } export function TreeKeyProvider({children}: TreeKeyProviderProps) { const [key, setKey] = React.useState<string>(''); return ( <TreeKeyContext.Provider value={key}> <TreeKeyDispatchContext.Provider value={setKey}> {children} </TreeKeyDispatchContext.Provider> </TreeKeyContext.Provider> ); } export function useTreeKey() { const key = React.useContext(TreeKeyContext); if (key === undefined) { throw new Error('useTreeKey must be used within a TreeKeyProvider'); } return key; } export function useDispatchTreeKey() { const updateKey = React.useContext(TreeKeyDispatchContext); if (updateKey === undefined) { throw new Error('useDispatchTreeKey must be used within a TreeKeyProvider'); } return updateKey; } // Use for components that can render outside the schema tree layout. // Strict consumers should keep using useDispatchTreeKey to catch missing providers. export function useOptionalDispatchTreeKey() { return React.useContext(TreeKeyDispatchContext); }