[英]How to use react-intl 2 with redux?
How to use injectintl along with connect in the application using react-intl 2.0 and redux. 如何使用react-intl 2.0和redux在应用程序中同时使用injectintl和connect。 See the last two lines of my code and tell me what is the proper way of doing that.
请参阅代码的最后两行,并告诉我这样做的正确方法是什么。
import React from 'react';
import { deleteTodo } from '../actions/todoActions';
import { connect } from 'react-redux';
import {
injectIntl,
FormattedRelative,
FormattedNumber
} from 'react-intl';
class TodoItem extends React.Component {
working() {
console.log('well it\'s working');
}
render() {
return (<p className="light" key={this.props.index}>
{this.props.todo} <a className="red-text text-accent-3" href="#" onClick={e =>
{
this.props.dispatch(deleteTodo(this.props.index))
}}>x</a>
</p>);
}
}
function mapStateToProps() {
return {
}
}
let injectedIntl = injectIntl(TodoItem);
export default connect(mapStateToProps, null, null, {withRef: true})(injectedIntl);
You can wrap as follows: 您可以包装如下:
export default injectIntl(
connect(mapStateToProps, null, null, { withRef: true }
)(TodoItem))
我认为这个库可以帮助您https://github.com/ratson/react-intl-redux
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.