mirror of
https://github.com/HSLdevcom/digitransit-ui
synced 2025-11-29 17:03:33 +01:00
24 lines
643 B
JavaScript
24 lines
643 B
JavaScript
import React, { createContext, useContext } from 'react';
|
|
import { PropTypes } from 'prop-types';
|
|
import { configShape } from '../util/shapes';
|
|
|
|
const ConfigContext = createContext();
|
|
|
|
export function ConfigProvider({ value, children }) {
|
|
return (
|
|
<ConfigContext.Provider value={value}>{children}</ConfigContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function useConfigContext() {
|
|
const context = useContext(ConfigContext);
|
|
if (!context) {
|
|
throw new Error('useConfigContext must be used within a ConfigProvider');
|
|
}
|
|
return context;
|
|
}
|
|
|
|
ConfigProvider.propTypes = {
|
|
value: configShape.isRequired,
|
|
children: PropTypes.node.isRequired,
|
|
};
|