Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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} &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);
like image 965
Ali Raza Avatar asked Apr 19 '16 12:04

Ali Raza


1 Answers

You can wrap as follows:

export default injectIntl(
  connect(mapStateToProps, null, null, { withRef: true }
)(TodoItem))
like image 188
Darren Shewry Avatar answered Oct 12 '22 22:10

Darren Shewry