Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

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

Open
Spenhouet opened this issue Jun 11, 2018 · 6 comments
Open

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

Spenhouet opened this issue Jun 11, 2018 · 6 comments

Comments

@Spenhouet
Copy link

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
Copy link
Author

This error comes from this commit: #105

@Spenhouet
Copy link
Author

Reverting "react-scripts" to "0.9.5" helps

"react-scripts": "0.9.5"

@Taroka
Copy link

Taroka commented Jul 12, 2018

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
Copy link
Author

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

@rc6886
Copy link

rc6886 commented Jul 30, 2018

@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
Copy link

ezorfa commented Aug 28, 2020

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants