Skip to content

Instantly share code, notes, and snippets.

@marsen
Last active October 3, 2021 16:50
Show Gist options
  • Save marsen/0f0cb09c7a45fe3ff3c7b2afac9e27bd to your computer and use it in GitHub Desktop.
Save marsen/0f0cb09c7a45fe3ff3c7b2afac9e27bd to your computer and use it in GitHub Desktop.
i18n side effect solution
export const changingLanguageAction =
(language:'en'|'zh'): ThunkAction<
void,
LanguageState,
unknown,
LanguageActionTypes
> =>
async (dispatch,getState) => {
i18n.changeLanguage(language);
dispatch(changeLanguageAction(language));
};
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