NEXT.js isomorphic-unfetch errs out










0















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?










share|improve this question


























    0















    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?










    share|improve this question
























      0












      0








      0








      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 4:24









      GuruGuru

      1,79852342




      1,79852342






















          1 Answer
          1






          active

          oldest

          votes


















          1














          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.






          share|improve this answer























          • That's true. It did the trick. Glad you explained what it is as well.

            – Guru
            Nov 13 '18 at 4:54










          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
          );



          );













          draft saved

          draft discarded


















          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









          1














          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.






          share|improve this answer























          • That's true. It did the trick. Glad you explained what it is as well.

            – Guru
            Nov 13 '18 at 4:54















          1














          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.






          share|improve this answer























          • That's true. It did the trick. Glad you explained what it is as well.

            – Guru
            Nov 13 '18 at 4:54













          1












          1








          1







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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

















          • 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

















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Kleinkühnau

          Makov (Slowakei)

          Deutsches Schauspielhaus