fix typing error
This commit is contained in:
@@ -4,9 +4,6 @@ const withBundleAnalyzer = require("@next/bundle-analyzer")({
|
||||
|
||||
module.exports = withBundleAnalyzer({
|
||||
target: "server",
|
||||
publicRuntimeConfig: {
|
||||
localeSubpaths: {},
|
||||
},
|
||||
images: {
|
||||
domains: [
|
||||
"sahkoinsinoorikilta.fi",
|
||||
|
||||
+14
-14
@@ -24,11 +24,13 @@ const translateFi: TranslateFunc = (key) => {
|
||||
};
|
||||
|
||||
interface Store {
|
||||
language: string
|
||||
language: string;
|
||||
changeLanguage: React.Dispatch<string>,
|
||||
}
|
||||
|
||||
const initialState: Store = {
|
||||
language: "fi",
|
||||
changeLanguage: null,
|
||||
};
|
||||
|
||||
const Reducer = (state: Store, action: string) => {
|
||||
@@ -48,24 +50,22 @@ const Reducer = (state: Store, action: string) => {
|
||||
}
|
||||
};
|
||||
|
||||
const Context = createContext(initialState);
|
||||
const LocaleContext = createContext(initialState);
|
||||
|
||||
const LocaleStore: React.FC = ({ children }) => (
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
<Context.Provider value={useReducer(Reducer, initialState)}>
|
||||
{children}
|
||||
</Context.Provider>
|
||||
);
|
||||
const LocaleStore: React.FC = ({ children }) => {
|
||||
const [state, changeLanguage] = useReducer(Reducer, initialState);
|
||||
|
||||
return (
|
||||
<LocaleContext.Provider value={{ ...state, changeLanguage }}>
|
||||
{children}
|
||||
</LocaleContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default LocaleStore;
|
||||
|
||||
const useTranslation = () => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
const [state, changeLanguage] = useContext(Context);
|
||||
|
||||
const { language } = state;
|
||||
const { language, changeLanguage } = useContext(LocaleContext);
|
||||
const t = language === "en" ? translateEn : translateFi;
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user