SWR the data fetching hero of ReactJS // 5 minute tutorial

preview_player
Показать описание
In this tutorial we will look at why fetching data with useEffect is a bad idea even when only done on client side and how SWR can solve this and many other issues for you 🌹

Relevant Tutorials 🎥

-- Part of ReactJS TIPs for Professionals --
Members (no-ads 🌹, early release ⚡️, supported by you 🙏🏻):
Subscribers (free 🤗, scheduled release ⏱, use the notification bell 🔔):

🏷 #basarat #5MinutesOrLess #React #JavaScript #Tutorial #TypeScript

👇 ❤️ Subscribe for MOORE ❤️ 👇

**Feel Free To Read This Lot**

I'm Basarat, and I love helping developers. More about me:

Microsoft MVP for TypeScript
200K contributions on Stackoverflow. Top Contributor for TypeScript.
Book Author: Beginning NodeJS
Book Author: TypeScript Deep Dive
Creator of multiple hot ✨ed Github Open Source projects

Рекомендации по теме
Комментарии
Автор

I like how simple swr is but the way you mutate the state I feel that tanstackQuery might be better. I also like the fact that swr is a single package, you did the same for zod, you clarify a lot of things in these short videos. You are my favorite teacher 😁

ftnsco
Автор

thanks Basarat...so useful and timely. Just started a new nextJs project, and noticed the swr reference in the docs. Your vid helped me realize how it saves a network call from the usual 2 calls from useEffect😀

uquantum
Автор

i 'm a bit disappointed u didn't do the mutation part but anyway great video!

nested
Автор

I like the way you explain these things, thank you :)

muratasarslan
Автор

Great explanation. Simple Fast and to the point

KingOfCorinth
Автор

what if i export fetched data from SWR? and import in different component, like state managment? ...

idontknowWhatTosay
Автор

well done. that is all i can say. thank you

tube-rpnb
Автор

Thank you.

Are there any advantages when you compare SWR with react-query? They seem to perform similar tasks ☘️

noccer
Автор

Could also remove the React.StrictMode tags, but from what I have read the two calls only happens in dev, and not in deployment, but I have not tested it myself, though if that is true, I would go with having one less dependency.

MrSuperNova
Автор

Hello, the first argument is not the API endpoint I think but a unique identifier for the fetch. It can be anything.
Also, where is your fetcher function?
Thanks !

z_
Автор

By the way, strict mode is only enabled in development, so only one request will be sent in production.

ogreeni
Автор

The first argument in useSWR is the unique key to identify that data call right?

hollymolly
Автор

Hello, the first argument is not the API endpoint I think but a unique identifier for the fetch. It can be anything.
Also, where is your fetcher function?
‘Thanks !

z_
Автор

Strict mode checks are run in development mode only; they do not impact the production build

basharkhadra