erikras / react-redux-universal-hot-example

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

@asyncConnect is not called again when the route is changed #1376

Closed quentinwalter closed 6 years ago

quentinwalter commented 7 years ago

When I load the page the first time, I can see the projects loaded with @asyncConnect. But if I go to another route and come back through Link or pushState, the function loadProjects is not called and the state.projects has only the loaded property set to false.

@asyncConnect([{
  deferred: true,
  promise: ({ store: { dispatch, getState } }) => {
    if (!isLoaded(getState())) {
      return dispatch(loadProjects());
    }
  }
}])
@connect(
  state => ({
    projects: state.projects.data,
  }),
  { ...projectActions, initialize })
export default class Projects extends Component {
  // render projects
}

Maybe I don't understand how @asyncConnect work but it seems that it should be called everytime one accesses its route.

dattran92 commented 7 years ago

check the condition here !isLoaded(getState()). If your data is loaded, then it won't load again.