fix typing error

This commit is contained in:
Aarni Halinen
2021-04-04 22:39:14 +03:00
parent 2763b8ee6e
commit f8f433463f
2 changed files with 14 additions and 17 deletions
-3
View File
@@ -4,9 +4,6 @@ const withBundleAnalyzer = require("@next/bundle-analyzer")({
module.exports = withBundleAnalyzer({
target: "server",
publicRuntimeConfig: {
localeSubpaths: {},
},
images: {
domains: [
"sahkoinsinoorikilta.fi",
+14 -14
View File
@@ -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 {