react-redux-realworld-example-app icon indicating copy to clipboard operation
react-redux-realworld-example-app copied to clipboard

Unhandled Rejection (TypeError): Cannot read property '0' of null

Open Spenhouet opened this issue 6 years ago • 6 comments

I cloned the current state of this repo and directly started it:

npm install
npm start

And directly get this error:

Unhandled Rejection (TypeError): Cannot read property '0' of null
./src/reducers/articleList.js.__webpack_exports__.a
C:/dev/Aufgabe/FeatureImage/react-redux-realworld-example-app/src/reducers/articleList.js:53
  50 | return {
  51 |   ...state,
  52 |   pager: action.pager,
> 53 |   tags: action.payload[0].tags,
  54 |   articles: action.payload[1].articles,
  55 |   articlesCount: action.payload[1].articlesCount,
  56 |   currentPage: 0,

Spenhouet avatar Jun 11 '18 09:06 Spenhouet

This error comes from this commit: #105

Spenhouet avatar Jun 11 '18 09:06 Spenhouet

Reverting "react-scripts" to "0.9.5" helps

"react-scripts": "0.9.5"

Spenhouet avatar Jun 11 '18 10:06 Spenhouet

Hi I reverted to "0.9.5", the application won't crash. However, the items (comments, tags) cannot load. Always stay in "Loading". Any thought?

Taroka avatar Jul 12 '18 00:07 Taroka

@Taroka I don't think that is related to this issue.

Spenhouet avatar Jul 12 '18 19:07 Spenhouet

@Spenhouet @Taroka

In ~\src\components\Home\index.js change line 37 from:

this.props.onLoad(tab, articlesPromise, Promise.all([agent.Tags.getAll(), articlesPromise()]));

to

Promise
   .all([agent.Tags.getAll(), articlesPromise()])
   .then((result) => {
     this.props.onLoad(tab, articlesPromise, result);
   });

The issue is the promise is being passed to the reducer before the API calls have finished. Ideally, that would be in a thunk so the component isn't making API calls directly (nor do you run into this particular issue). But it looks like that is done everywhere.

I'm not sure if this is the correct fix since I assume this has been working for some time since that line hasn't changed in a year. But this should help you work around the issue until someone more knowledgeable with the code base can do a true fix.

Hope this helps.

rc6886 avatar Jul 30 '18 00:07 rc6886

@Spenhouet After changing the scripts version, it shows no error but is forever loading! Are you using django backend?

ezorfa avatar Aug 28 '20 07:08 ezorfa