Fetch json data from a url in React (and NextJS) - 3 easy ways

Поделиться
HTML-код
  • Опубликовано: 29 авг 2024
  • Let's look at 3 ways to fetch JSON data from an API using the Fetch API and NextJS's getServerSideProps. I'll show you all 3 options, any of which you can use to get data from JSON and display it on your page.
    This is very common especially for displaying dynamic content from say a blog or portfolio. There is hardly a project today that doesn't require some sort of fetching from an external API. Let's go.
    CONNECT ON MY DISCORD:
    / discord
    Twitter: / omarel
    GitHub: github.com/oel...
    #fetchdata #react #nextjs #getserversideprops

Комментарии • 14

  • @lucaslopes1260
    @lucaslopes1260 2 года назад +1

    Awesome video, bro! The channel has few subscribers so far, but I can see it will become huge. Keep up the good work!

  • @SuperValza
    @SuperValza Год назад

    Best video so far about getServerSideProps. Keep up good work.
    I assume you will get many subscription if you will continue with such type of videos. Basic stuff but super usefull. Thanks.

  • @siavashakrami3444
    @siavashakrami3444 2 года назад

    Thank you! I took my first step into React world today. Cheers!

    • @thedigitalceo
      @thedigitalceo  2 года назад

      Nice! Go for it and don’t look back 😎

  • @derickio
    @derickio Год назад +1

    I also want to point out that the advantage of getServerSideProps() is that it runs on server-side code --- so if your API response doesn't have "Access-Control-Allow-Origin" in its header, then it will still work.
    If you try to do the other two options with an "unfriendly API" you will run into a CORS error... which can be really frustrating.

  • @mynameisibukun
    @mynameisibukun Год назад +2

    thank you so much!!!!

  • @IsThisBenton
    @IsThisBenton 2 года назад +1

    Great video, thanks

  • @matees2162
    @matees2162 2 года назад +1

    thank you so much

  • @cristeaadrian9682
    @cristeaadrian9682 Год назад +1

    thank you

  • @jaypatel6775
    @jaypatel6775 Год назад

    Nice explanation. Please provide code that you write in this video

  • @KonstantinM-nuu
    @KonstantinM-nuu Год назад

    If I may ask something again.. I want to map over the data but define an addtional requirement like "completed === true". So just return all titles when the property of completed is true. Can someone help? Thanks :)

  • @nayablone215
    @nayablone215 Год назад

    thats great, one question , how can you pull a data if its coming from GRAHPHQL querry ? will the same method work or do we need to use different method? Thank you!

  • @KonstantinM-nuu
    @KonstantinM-nuu Год назад

    Sorry to bother, but why do I get the error .map is not a function? Thanks for any advise!

    • @thedigitalceo
      @thedigitalceo  Год назад

      I imagine something is wrong with the array variable you are trying to map. Maybe it’s undefined or not an array. That’s my guess. Try to comment out the map and console log the array first and see what it shows.