Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as types from '../constants/ActionsTypes'
- let initialState = {
- city: '',
- weather: [],
- loadMore: 5
- };
- const weather = (state = initialState, action) => {
- switch (action.type) {
- case types.ADD_WEATHER:
- return Object.assign({}, state, {
- city: action.cityName,
- weather: [
- ...action.cityWeather
- ],
- loadMore: 5
- });
- default:
- return state;
- }
- }
- export default weather;
- import * as types from '../constants/ActionsTypes'
- let initialState = {
- city: '',
- weather: [],
- loadMore: 5
- };
- const loadMore = (state = initialState, action) => {
- switch (action.type) {
- case types.LOAD_MORE:
- return Object.assign({}, state, {
- ...state, // when I click 'load more' the state is empty
- loadMore: action.loadMore
- });
- default:
- return state;
- }
- }
- export default loadMore;
- import * as types from '../constants/ActionsTypes'
- import { combineReducers } from 'redux';
- import weather from './addWeather';
- import loadMore from './loadMore';
- const reducers = combineReducers({
- weather,
- loadMore
- });
- export default reducers;
- import React, { Component } from 'react';
- import { connect } from 'react-redux';
- import { moreWeather } from '../actions'
- import loadMoreComponent from '../components/loadMore'
- const mapStateToProps = state => (console.log('loadMoreComponent', state), {
- state: state.weather
- });
- const mapDispatchToProps = dispatch => ({
- moreWeather: (loadMore) => dispatch(moreWeather(loadMore))
- });
- export default connect(
- mapStateToProps,
- mapDispatchToProps)(loadMoreComponent);
- import React, { Component } from 'react';
- import { connect } from 'react-redux';
- import WheatherLayoutComponent from '../components/WheatherLayout'
- const mapStateToProps = state => (console.log('WheatherLayoutComponent ', state), {
- cityStore: state.weather
- });
- export default connect(
- mapStateToProps,
- null)(WheatherLayoutComponent);
- (state, action) => {
- weather: weatherReducer(state, action)
- loadMore: loadMoreReducer( state, action)
- }
- const mapStateToProps = state => (console.log('loadMoreComponent', state), {
- state: state.loadMore // not state.weather
- });
Add Comment
Please, Sign In to add comment