如何使用react-intl 2和redux?

时间:2016-04-19 12:06:37

标签: reactjs redux react-redux react-intl

如何使用react-intl 2.0和redux在应用程序中使用injectintl和connect。请参阅我的代码的最后两行,并告诉我这样做的正确方法。

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} &nbsp;&nbsp;<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);

2 个答案:

答案 0 :(得分:4)

您可以按如下方式进行换行:

export default injectIntl(
  connect(mapStateToProps, null, null, { withRef: true }
)(TodoItem))

答案 1 :(得分:0)

我认为这个图书馆可以帮助你https://github.com/ratson/react-intl-redux