heron2014 / weather-redux-app

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

Flow of thinking about redux #7

Open heron2014 opened 8 years ago

heron2014 commented 8 years ago

First question is : Is the next component is going to be container?

If is going to be container, this is the the flow:

import {connect } from 'react-redux'

class WeatherList extends Component {

  render() {
    return (
      <table className="table table-hover">
        <thead>
          <tr>
            <th>City</th>
            <th>Temperature</th>
            <th>Pressure</th>
            <th>Humidity</th>
          </tr>
        </thead>
        <tbody>
        </tbody>
      </table>
    );
  }
}

function mapStateToProps(state) {
  return {weather: state.weather}  // this weather comes from reducer
}

//es6 syntax
function mapStateToProps({ weather }) {
  return {weather};
}

//connect our data with the current component

export default connect(mapStateToProps)(WeatherList)

so now you can access weather in the inside component - this.props.weather