react-intl FormattedMessage在注册reduxForm后没有更新

时间:2018-04-24 20:04:57

标签: reactjs redux react-redux redux-form react-intl

使用reduxForm注册组件后,react-intl FormattedMessages在状态更改后不会更新:

import React from 'react';
import { reduxForm } from 'react-redux-form';
import { Form } from 'reactstrap';
import { FormattedMessage } from 'react-intl';

const ExampleForm = ({ handleSubmit }) => (
  <Form onSubmit={handleSubmit}>
    <h2>
      <FormattedMessage id="example.title" />
    </h2>
    ...
  </Form>
);

// When added reduxForm FormattedMessages are not displaying
// correct translation after language locale change through reducer
export default reduxForm({
  form: 'example',
})(ExampleForm);

// If I I am using without reduxForm everything works correctly
// export default ExampleForm;

有没有人有这方面的经验?对我来说,他们只有在我离开路线并返回时才会更新,或者当我正在将我的语言环境写入localStorage动作并在商店初始化中阅读时,只更新页面。

Lib版本:

"react": "^16.3.2",
"redux": "^4.0.0",
"react-redux": "^5.0.7",
"redux-form": "^7.3.0",
"react-intl": "^2.4.0",
"react-intl-redux": "^0.7.0",

1 个答案:

答案 0 :(得分:0)

包裹injectIntl需要

reduxForm

import { FormattedMessage, injectIntl } from 'react-intl';

export default injectIntl(reduxForm({
  form: 'example',
})(ExampleForm));