erikras / react-redux-universal-hot-example

A starter boilerplate for a universal webapp using express, react, redux, webpack, and react-transform
MIT License
12.01k stars 2.5k forks source link

multiple api calls - only one single action.result #1361

Open sunaram opened 7 years ago

sunaram commented 7 years ago

i have created a container similar to src/components/InfoBar/InfoBar.js which is connected to a reducer ("posts"). the reducer has the "load" method defined just like info.js reducer "module". i have verified that all the intended data are retrieved from their respective endpoints. the issue is that depending on what order the "load" methods are called in src\App\App.js, I get the data from last called "load" method. src\App\App.js

import { isLoaded as isInfoLoaded, load as loadInfo } from 'redux/modules/info';
import { isLoaded as isPostsLoaded, load as getPosts } from 'redux/modules/posts';
import { isLoaded as isAuthLoaded, load as loadAuth, logout } from 'redux/modules/auth';
.......
@asyncConnect([{
  promise: ({store: {dispatch, getState}}) => {
    const promises = [];
    if (!isPostsLoaded(getState())) {
      promises.push(dispatch(getPosts()));
    }
    if (!isInfoLoaded(getState())) {
      promises.push(dispatch(loadInfo()));
    }
    if (!isAuthLoaded(getState())) {
      promises.push(dispatch(loadAuth()));
    }

    return Promise.all(promises);
  }
}])

Here is my LOAD_SUCCESS defined in info.js and posts.js (a reducer "module" created by me) respectively

case LOAD_SUCCESS:
      return {
        ...state,
        loading: false,
        loaded: true,
        data: action.result
      };
case LOAD_SUCCESS:
      return {
        ...state,
        posts_loading: false,
        posts_loaded: true,
        data: action.result
      };

Here is my current state for "info" and "posts" http://prntscr.com/e02qxi Can anyone explain why my api call data replaces the previous api call data? And where can I fix it?

kunalbhatt commented 7 years ago

@rageai getting this same issue. Anyone know of a fix?

kunalbhatt commented 7 years ago

Anyone know which dependency is causing this issue? I've been pulling my hair out on this one. @rageai if you found something please let me know.