-
Use SWR with React Suspense
This article will explore how you should use the awesome useSWR hook for remote data fetching. Why the SWR hooks for remote data fetching? Because SWR (stale-while-revalidate) is a fully dedicated React Hooks library for remote data fetching. So basically, this is what SWR does: First returns the data from cache (stale) Then sends the fetch request (revalidate). Finally comes with the up-to-date data again. Why Suspense? Because Suspense will definitely help you to maintain a consistent UI in the face of asynchronous dependencies. Something I prefer to call on-demand loaded React components. All you need is to: Set the suspense: true as one of the useSWR hook options. Wrap…