I'm migrating my react-admin app to v3.
It uses a custom redux-saga effect (USER_CHECK_SUCCESS
) to call the changeLocale
method but that's not supported anymore : https://marmelab.com/blog/2019/10/10/react-admin-v3-i18n.html
Problem is, I don't know how to re-implement it, I can't use the useSetLocale
hook since I'm not running inside of a react component.
import {
USER_LOGIN_SUCCESS,
USER_CHECK,
USER_CHECK_SUCCESS,
changeLocale
} from "react-admin";
import {takeEvery, put} from "redux-saga/effects";
export default function* authSagas() {
// takeEvery deprecated ? removed ? https://github.com/redux-saga/redux-saga/releases/tag/v1.0.0
yield takeEvery(USER_LOGIN_SUCCESS, handleLanguage);
yield takeEvery(USER_CHECK, handleLanguage);
yield takeEvery(USER_CHECK_SUCCESS, handleLanguage);
}
export function* handleLanguage(action) {
if(!localStorage.getItem('authenticated')){
return;
}
const user = JSON.parse(localStorage.getItem('authenticated'));
if(user.locale){
// Should try/catch ? https://github.com/redux-saga/redux-saga/releases/tag/v1.0.0
yield put(changeLocale(user.locale));
}
}