/
vshmidt
/
label-studio
Обзор
Документация
Войти
/
vshmidt
/
label-studio
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
web/apps/labelstudio/src/providers/ConfigProvider.jsx
29 строк
724 B
Raul Martin
refactor: echo 27: Introducing biome (#5759)
29 апр 2024, 11:39
Не верифицирован
29 апр 2024, 11:39
2660ec9
Код
Авторство
О чём код?
import { createContext, useContext, useMemo, useState } from "react"; export const ConfigContext = createContext(window.APP_SETTINGS); ConfigContext.displayName = "ConfigContext"; export const ConfigConsumer = ConfigContext.Consumer; export const ConfigProvider = ({ children }) => { const [config, setConfig] = useState(window.APP_SETTINGS ?? {}); const update = (newConfig) => { if (!newConfig) return; setConfig(newConfig); }; const contextValue = useMemo(() => { return { ...config, update, }; }, [config]); return <ConfigContext.Provider value={contextValue}>{children}</ConfigContext.Provider>; }; export const useConfig = () => { return useContext(ConfigContext); };