gothinkster / react-redux-realworld-example-app

Exemplary real world application built with React + Redux
https://react-redux.realworld.io
MIT License
5.55k stars 2.5k forks source link

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

Open Spenhouet opened 6 years ago

Spenhouet commented 6 years ago

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 commented 6 years ago

This error comes from this commit: #105

Spenhouet commented 6 years ago

Reverting "react-scripts" to "0.9.5" helps

"react-scripts": "0.9.5"

Taroka commented 5 years ago

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?

Spenhouet commented 5 years ago

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

rc6886 commented 5 years ago

@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.

ezorfa commented 3 years ago

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