Overview
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