【问题标题】:How to use react-intl 2 with redux?如何将 react-intl 2 与 redux 一起使用?
【发布时间】:2016-08-11 14:26:36
【问题描述】:

如何在使用 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);

【问题讨论】:

  • 它不起作用吗?似乎是对的..

标签: reactjs redux react-redux react-intl


【解决方案1】:

你可以这样换行:

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

【讨论】:

    【解决方案2】:

    我觉得这个库可以帮到你https://github.com/ratson/react-intl-redux

    【讨论】:

      猜你喜欢
      • 2018-11-15
      • 1970-01-01
      • 2019-02-20
      • 2020-01-06
      • 2021-07-07
      • 1970-01-01
      • 1970-01-01
      • 2019-02-05
      • 2017-12-09
      相关资源
      最近更新 更多