NEXT.js isomorphic-unfetch errs out
I am doing the following exercise on Next.js remote fetching. What I am not able to understand and adapt is the exercise fetches data from http://api.tvmaze.com.
Data is like:
[
"score":24,"show":"id":975,"url":"", "name":""
,"score":25,"show":"id":976,"url":"", "name":""
,"score":26,"show":"id":977,"url":"", "name":""
]
The index page uses the following mapping:
props.shows.map((show) => (
<li key=show.id>
<Link as='/p/$show.id' href='/post?id=$show.id'>
<a>show.name</a>
</Link>
</li>
))
Note, it has "score":"", "show": structure. So, the props.shows.map uses a variable show and refers to show.id and show.name. And it works fine. I am confused to understand how does it work? Because id is nestled inside and to me it should be show.show.id.
Also, I am trying to fetch a different source of data that has slightly different structure.
[
"id": 1, "name":"name1"
,"id": 2, "name":"name2"
,"id": 3, "name":"name3"
]
The same code fails with error:
Unhandled Rejection (TypeError): Cannot read property 'id' of undefined
So, apart from it has obviously different data structure. I could not understand why, if my data structure is slightly different, how do I change the props.shows.map function change accordingly?
javascript next.js
add a comment |
I am doing the following exercise on Next.js remote fetching. What I am not able to understand and adapt is the exercise fetches data from http://api.tvmaze.com.
Data is like:
[
"score":24,"show":"id":975,"url":"", "name":""
,"score":25,"show":"id":976,"url":"", "name":""
,"score":26,"show":"id":977,"url":"", "name":""
]
The index page uses the following mapping:
props.shows.map((show) => (
<li key=show.id>
<Link as='/p/$show.id' href='/post?id=$show.id'>
<a>show.name</a>
</Link>
</li>
))
Note, it has "score":"", "show": structure. So, the props.shows.map uses a variable show and refers to show.id and show.name. And it works fine. I am confused to understand how does it work? Because id is nestled inside and to me it should be show.show.id.
Also, I am trying to fetch a different source of data that has slightly different structure.
[
"id": 1, "name":"name1"
,"id": 2, "name":"name2"
,"id": 3, "name":"name3"
]
The same code fails with error:
Unhandled Rejection (TypeError): Cannot read property 'id' of undefined
So, apart from it has obviously different data structure. I could not understand why, if my data structure is slightly different, how do I change the props.shows.map function change accordingly?
javascript next.js
add a comment |
I am doing the following exercise on Next.js remote fetching. What I am not able to understand and adapt is the exercise fetches data from http://api.tvmaze.com.
Data is like:
[
"score":24,"show":"id":975,"url":"", "name":""
,"score":25,"show":"id":976,"url":"", "name":""
,"score":26,"show":"id":977,"url":"", "name":""
]
The index page uses the following mapping:
props.shows.map((show) => (
<li key=show.id>
<Link as='/p/$show.id' href='/post?id=$show.id'>
<a>show.name</a>
</Link>
</li>
))
Note, it has "score":"", "show": structure. So, the props.shows.map uses a variable show and refers to show.id and show.name. And it works fine. I am confused to understand how does it work? Because id is nestled inside and to me it should be show.show.id.
Also, I am trying to fetch a different source of data that has slightly different structure.
[
"id": 1, "name":"name1"
,"id": 2, "name":"name2"
,"id": 3, "name":"name3"
]
The same code fails with error:
Unhandled Rejection (TypeError): Cannot read property 'id' of undefined
So, apart from it has obviously different data structure. I could not understand why, if my data structure is slightly different, how do I change the props.shows.map function change accordingly?
javascript next.js
I am doing the following exercise on Next.js remote fetching. What I am not able to understand and adapt is the exercise fetches data from http://api.tvmaze.com.
Data is like:
[
"score":24,"show":"id":975,"url":"", "name":""
,"score":25,"show":"id":976,"url":"", "name":""
,"score":26,"show":"id":977,"url":"", "name":""
]
The index page uses the following mapping:
props.shows.map((show) => (
<li key=show.id>
<Link as='/p/$show.id' href='/post?id=$show.id'>
<a>show.name</a>
</Link>
</li>
))
Note, it has "score":"", "show": structure. So, the props.shows.map uses a variable show and refers to show.id and show.name. And it works fine. I am confused to understand how does it work? Because id is nestled inside and to me it should be show.show.id.
Also, I am trying to fetch a different source of data that has slightly different structure.
[
"id": 1, "name":"name1"
,"id": 2, "name":"name2"
,"id": 3, "name":"name3"
]
The same code fails with error:
Unhandled Rejection (TypeError): Cannot read property 'id' of undefined
So, apart from it has obviously different data structure. I could not understand why, if my data structure is slightly different, how do I change the props.shows.map function change accordingly?
javascript next.js
javascript next.js
asked Nov 13 '18 at 4:24
GuruGuru
1,79852342
1,79852342
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Are you familiar with object destructuring in JS? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
In the example, writing (show) is shorthand for writing something like (resp) and then later show = resp.show. So in this case, due to destructuring, show already is the show object. Therefore, id works.
Your data doesn't have a show property, so when destructuring, show is undefined. And, of course, you can't get a property of undefined. Removing the curly braces from show should do the trick.
That's true. It did the trick. Glad you explained what it is as well.
– Guru
Nov 13 '18 at 4:54
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273784%2fnext-js-isomorphic-unfetch-errs-out%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Are you familiar with object destructuring in JS? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
In the example, writing (show) is shorthand for writing something like (resp) and then later show = resp.show. So in this case, due to destructuring, show already is the show object. Therefore, id works.
Your data doesn't have a show property, so when destructuring, show is undefined. And, of course, you can't get a property of undefined. Removing the curly braces from show should do the trick.
That's true. It did the trick. Glad you explained what it is as well.
– Guru
Nov 13 '18 at 4:54
add a comment |
Are you familiar with object destructuring in JS? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
In the example, writing (show) is shorthand for writing something like (resp) and then later show = resp.show. So in this case, due to destructuring, show already is the show object. Therefore, id works.
Your data doesn't have a show property, so when destructuring, show is undefined. And, of course, you can't get a property of undefined. Removing the curly braces from show should do the trick.
That's true. It did the trick. Glad you explained what it is as well.
– Guru
Nov 13 '18 at 4:54
add a comment |
Are you familiar with object destructuring in JS? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
In the example, writing (show) is shorthand for writing something like (resp) and then later show = resp.show. So in this case, due to destructuring, show already is the show object. Therefore, id works.
Your data doesn't have a show property, so when destructuring, show is undefined. And, of course, you can't get a property of undefined. Removing the curly braces from show should do the trick.
Are you familiar with object destructuring in JS? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
In the example, writing (show) is shorthand for writing something like (resp) and then later show = resp.show. So in this case, due to destructuring, show already is the show object. Therefore, id works.
Your data doesn't have a show property, so when destructuring, show is undefined. And, of course, you can't get a property of undefined. Removing the curly braces from show should do the trick.
answered Nov 13 '18 at 4:38
mherzigmherzig
782818
782818
That's true. It did the trick. Glad you explained what it is as well.
– Guru
Nov 13 '18 at 4:54
add a comment |
That's true. It did the trick. Glad you explained what it is as well.
– Guru
Nov 13 '18 at 4:54
That's true. It did the trick. Glad you explained what it is as well.
– Guru
Nov 13 '18 at 4:54
That's true. It did the trick. Glad you explained what it is as well.
– Guru
Nov 13 '18 at 4:54
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273784%2fnext-js-isomorphic-unfetch-errs-out%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown