Move context to a "state" folder
This commit is contained in:
parent
96bf56b8c1
commit
eecdb62dda
@ -1,47 +0,0 @@
|
||||
import React, { useState, createContext, useContext } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const AppContext = createContext(null);
|
||||
|
||||
export const useAppContext = () => useContext(AppContext);
|
||||
|
||||
const AppContextProvider = ({ children }) => {
|
||||
const [config, setConfig] = useState(null);
|
||||
|
||||
const get = ({ configKey = null }) => {
|
||||
if (configKey) {
|
||||
return config[configKey];
|
||||
}
|
||||
|
||||
return config;
|
||||
};
|
||||
|
||||
const add = ({ configKey, value }) => {
|
||||
setConfig(s => ({
|
||||
...s,
|
||||
[configKey]: value,
|
||||
}));
|
||||
};
|
||||
|
||||
const remove = ({ configKey }) => {
|
||||
setConfig(s => ({
|
||||
...s,
|
||||
[configKey]: null,
|
||||
}));
|
||||
};
|
||||
|
||||
return (
|
||||
<AppContext.Provider value={{ get, add, remove }}>
|
||||
{children}
|
||||
</AppContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
AppContextProvider.propTypes = {
|
||||
children: PropTypes.oneOfType([
|
||||
PropTypes.arrayOf(PropTypes.node),
|
||||
PropTypes.node,
|
||||
]).isRequired,
|
||||
};
|
||||
|
||||
export default AppContextProvider;
|
||||
8
platform/viewer/src/state/appConfig.context.jsx
Normal file
8
platform/viewer/src/state/appConfig.context.jsx
Normal file
@ -0,0 +1,8 @@
|
||||
import { createContext } from 'react';
|
||||
|
||||
export const APP_CONFIG_DEFAULT_VALUE = {
|
||||
config: {},
|
||||
setCurrentConfig: () => {},
|
||||
};
|
||||
|
||||
export const appConfigContext = createContext(APP_CONFIG_DEFAULT_VALUE);
|
||||
Loading…
Reference in New Issue
Block a user