brocoders / redux-async-connect

It allows you to request async data, store them in redux state and connect them to your react component.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Router route change to asyncConnect()'d component loses helper?

blainegarrett opened this issue · comments

When I load page A and navigate to page B by clicking a react-router , I get an error about my asyncConnect helper being undefined, specifically TypeError: Cannot read property 'get' of undefined using a modified version of the api helper (https://github.com/erikras/react-redux-universal-hot-example/blob/master/src/helpers/ApiClient.js).

In the code below, I confirmed that on initial page load in the browser, asyncHelpers is an object in the form of {client: ... }

      <Provider store={store} key="provider">
          <Router render={(props) =>
            <ReduxAsyncConnect {...props} helpers={ asyncHelpers } />
        } history={history} routes={routes} />
      </Provider>

Here is one of the async methods. On initial page load, client is as expected. After routing (including back button), client is undefined.

export function getArticles() {
  return {
      types: [ ARTICLE_REQUEST, ARTICLE_SUCCESS, ARTICLE_FAILURE ],
      promise: (client) => {
          console.log(client); // logs correctly on initial load, but is undefined after routing
          return client.get('/api/articles')
      }
  }

Anything obvious come to mind?

Closing. I believe this was just my goof of not adding the reduxRouterMiddleware.