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

preview_player
Показать описание
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:

#fetchdata #react #nextjs #getserversideprops
Рекомендации по теме
Комментарии
Автор

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

lucaslopes
Автор

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.

SuperValza
Автор

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

siavashakrami
Автор

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.

derickio
Автор

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

KonstantinM-nuu
Автор

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

jaypatel
Автор

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!

nayablone
Автор

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

KonstantinM-nuu
visit shbcf.ru