From f8f433463fce40bf4f541d88466dca3cb8d6489d Mon Sep 17 00:00:00 2001 From: Aarni Halinen Date: Sun, 4 Apr 2021 22:39:14 +0300 Subject: [PATCH] fix typing error --- next.config.js | 3 --- src/i18n/index.tsx | 28 ++++++++++++++-------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/next.config.js b/next.config.js index 9501ea6..67cb2c3 100644 --- a/next.config.js +++ b/next.config.js @@ -4,9 +4,6 @@ const withBundleAnalyzer = require("@next/bundle-analyzer")({ module.exports = withBundleAnalyzer({ target: "server", - publicRuntimeConfig: { - localeSubpaths: {}, - }, images: { domains: [ "sahkoinsinoorikilta.fi", diff --git a/src/i18n/index.tsx b/src/i18n/index.tsx index ee175d7..a0c1506 100644 --- a/src/i18n/index.tsx +++ b/src/i18n/index.tsx @@ -24,11 +24,13 @@ const translateFi: TranslateFunc = (key) => { }; interface Store { - language: string + language: string; + changeLanguage: React.Dispatch, } 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 - - {children} - -); +const LocaleStore: React.FC = ({ children }) => { + const [state, changeLanguage] = useReducer(Reducer, initialState); + + return ( + + {children} + + ); +}; 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 {