使用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",
答案 0 :(得分:0)
injectIntl
需要 reduxForm
:
import { FormattedMessage, injectIntl } from 'react-intl';
export default injectIntl(reduxForm({
form: 'example',
})(ExampleForm));