mirror of
https://github.com/Alvin-Zilverstand/nginx-proxy-manager.git
synced 2026-11-28 00:47:54 +01:00
React
This commit is contained in:
355 files changed
+9308
-17813
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { createContext, type ReactNode, useContext, useState } from "react";
|
||||
import { getLocale } from "src/locale";
|
||||
|
||||
// Context
|
||||
export interface LocaleContextType {
|
||||
setLocale: (locale: string) => void;
|
||||
locale?: string;
|
||||
}
|
||||
|
||||
const initalValue = null;
|
||||
const LocaleContext = createContext<LocaleContextType | null>(initalValue);
|
||||
|
||||
// Provider
|
||||
interface Props {
|
||||
children?: ReactNode;
|
||||
}
|
||||
function LocaleProvider({ children }: Props) {
|
||||
const [locale, setLocaleValue] = useState(getLocale());
|
||||
|
||||
const setLocale = async (locale: string) => {
|
||||
setLocaleValue(locale);
|
||||
};
|
||||
|
||||
const value = { locale, setLocale };
|
||||
|
||||
return <LocaleContext.Provider value={value}>{children}</LocaleContext.Provider>;
|
||||
}
|
||||
|
||||
function useLocaleState() {
|
||||
const context = useContext(LocaleContext);
|
||||
if (!context) {
|
||||
throw new Error("useLocaleState must be used within a LocaleProvider");
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
export { LocaleProvider, useLocaleState };
|
||||
export default LocaleContext;
|
||||
Reference in new issue
Block a user