Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No re-render when locale changes, please add multi-locale example #65

Open
goodwin64 opened this issue Sep 9, 2019 · 1 comment
Open

Comments

@goodwin64
Copy link

Related to https://github.com/gtournie/redux-form-validators/blob/master/examples/src/index.js#L25.

I'm working with Redux-Saga and it watches for "CHANGE_LOCALE" action:

// saga
export function* changeLocaleSaga(action: routines.setLocaleAction) {
  yield call(LocaleService.configureReduxFormValiators, action.payload);
}

yield all([
  takeEvery(routines.CHANGE_LOCALE, changeLocaleSaga),
]);

And in Locale Service I mutate the Validators:

// Locale.service
function configureReduxFormValiators(locale: ISupportedLocale) {
  const messages = getTranslationsByLocale(locale);

  Validators.messages = {
    ...Validators.messages,
    email: messages['component.field.error.isNotValidEmail'],
  };
}

export const LocaleService = {
  // getTranslationsByLocale,
  // getSupportedLocaleByLocale,
  configureReduxFormValiators,
};

BUT the problem here that Validators mutation doesn't tell React to re-render.

Please advice.

@goodwin64
Copy link
Author

After some research, I've found value passed into IntlProvider.Context got changed, but the Error Message is rendered by ReduxForm's <Field /> component, which doesn't recognize any changes.

The possible solution is to connect every container with ReduxForm field with injectIntl. I hope there are other more elegant solutions to prevent duplicating a lot of code.

@goodwin64 goodwin64 changed the title Please add multi-locale example No re-render when locale changes, please add multi-locale example Sep 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant