Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't load data anymore after replacing redux-async-connect with redux-connect #57

Closed
crunchtime-ali opened this issue Jul 27, 2016 · 2 comments

Comments

@crunchtime-ali
Copy link

crunchtime-ali commented Jul 27, 2016

I'm trying to switch from redux-async-connect to redux-connect.
I migrated as done in this PR erikras/react-redux-universal-hot-example#1140

The problem is that once I replace all from 'redux-async-connect in import statements with redux-connect it doesn't fetch any data anymore.

This is part of an example page where I want to use redux-connect:

import React, {Component, PropTypes} from 'react';
import Helmet from 'react-helmet';
import { asyncConnect } from 'redux-async-connect';
import {connect} from 'react-redux';

@asyncConnect([{
  deferred: true,
  promise: ({
    store: {
      dispatch,
      getState,
    }
  }) => {
    if (!isLoaded(getState())) {
      return dispatch(load());
    }
  }
}])
@connect(
  state => ({
    items: state.invoice.data,
    error: state.invoice.error,
    loading: state.invoice.loading,
    loaded: state.invoice.loaded,
    messages: state.intl.messages,
  }),
  dispatch => ({dispatch})
)
@SherClockHolmes
Copy link

I am having a similar issue on the latest version, I reverted back to version 2.1.0 and it seems to work.

@AVVS
Copy link
Member

AVVS commented Jul 27, 2016

  1. filter doesnt work properly if you want to have different props loaded on server/client - check filter-ed promises not being executed in componentDidMount #30
import React, { Component, PropTypes } from 'react';
import Helmet from 'react-helmet';
import { asyncConnect } from 'redux-connect';

@asyncConnect([{
  promise: ({ store: { dispatch, getState } }) => {
     if (!isLoaded(getState())) {
        // must return promise!
        return dispatch(load());
    }
  }
}],
state => ({
  items: state.invoice.data,
  error: state.invoice.error,
  loading: state.invoice.loading,
  loaded: state.invoice.loaded,
  messages: state.intl.messages,
}))

This is optimized version of your code, since dispatch is passed by connect in any case

@AVVS AVVS closed this as completed Jul 31, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants