heron2014 / weather-redux-app

Weather app build in React and Redux
0 stars 0 forks source link

Pattern of adding action to the container (upgraded component) props #6

Open heron2014 opened 8 years ago

heron2014 commented 8 years ago

in your container:

Binding action to props

import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { your action } from '../action/index.js'

your component ...

function mapDispatchToProps(dispatch) {
  rerturn bindActionCreators({your action}, dispatch);
}

export default connect (null, mapDispatchToProps)(your container);

//null because we dont care about state? 
// now you can use action as props above like: this.props.YourAction ...
//dont forget to export only connect and not your class 

//dont forget to bind all methods to the correct object (this)