Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

The Best Way to Fetch Data from an API in React - SWR Preload & Optimistic UI

Dave Gray via YouTube

Overview

Save Big on Coursera Plus. 7,000+ courses at $160 off. Limited Time Only!
Explore an advanced approach to fetching data from APIs in React using SWR 2.0 Preload and Optimistic UI in this comprehensive 30-minute tutorial. Learn how to implement SWR React hooks for efficient data fetching, starting with an explanation of SWR and progressing through installation, setup with json-server, and creating an Axios API layer. Master the useSWR hook, understand mutations, and discover how to handle CRUD operations with added delay for realistic scenarios. Dive into SWR 2.0's preload functionality and the benefits of Optimistic UI updates. Follow along as the tutorial guides you through refactoring for Optimistic UI, creating helper functions, and implementing mutate with Optimistic UI. Conclude with a practical challenge to reinforce your newly acquired skills in this cutting-edge React data fetching technique.

Syllabus

Intro
Welcome
SWR Explained
Starter Code
Install SWR
json-server
Axios API layer
Imports
useSWR hook
SWR mutate function
What is a mutation?
Check the CRUD operations
Adding some delay
Viewing stale data until success or fail
SWR 2.0 Preload data
Benefits of Optimistic UI updates
Refactor to Optimistic UI
Helper functions
Import the helpers
Mutate with Optimistic UI
Checking the Optimistic UI
A Challenge for You

Taught by

Dave Gray

Reviews

Start your review of The Best Way to Fetch Data from an API in React - SWR Preload & Optimistic UI

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.