mirror of https://github.com/morpheus65535/bazarr
29 lines
614 B
TypeScript
29 lines
614 B
TypeScript
import { createContext, FunctionComponent, useContext } from "react";
|
|
|
|
const SettingsContext = createContext<Settings | null>(null);
|
|
|
|
export function useSettings() {
|
|
const context = useContext(SettingsContext);
|
|
|
|
if (context === null) {
|
|
throw new Error("useSettings must be used within a SettingsProvider");
|
|
}
|
|
|
|
return context;
|
|
}
|
|
|
|
type SettingsProviderProps = {
|
|
value: Settings;
|
|
};
|
|
|
|
export const SettingsProvider: FunctionComponent<SettingsProviderProps> = ({
|
|
value,
|
|
children,
|
|
}) => {
|
|
return (
|
|
<SettingsContext.Provider value={value}>
|
|
{children}
|
|
</SettingsContext.Provider>
|
|
);
|
|
};
|