Last active
October 3, 2021 16:50
-
-
Save marsen/0f0cb09c7a45fe3ff3c7b2afac9e27bd to your computer and use it in GitHub Desktop.
i18n side effect solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const changingLanguageAction = | |
(language:'en'|'zh'): ThunkAction< | |
void, | |
LanguageState, | |
unknown, | |
LanguageActionTypes | |
> => | |
async (dispatch,getState) => { | |
i18n.changeLanguage(language); | |
dispatch(changeLanguageAction(language)); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Middleware } from "redux"; | |
import i18n from "../../i18n/configs"; | |
import { CHANGE_LANGUAGE } from "../language/languageActions"; | |
export const actionTranslation: Middleware = | |
(storeAPI: any) => (next: any) => (action: any) => { | |
console.log('action translation') | |
if(action.type===CHANGE_LANGUAGE){ | |
i18n.changeLanguage(action.payload) | |
} | |
return next(action); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment