It's been amazing to see SWR flourish so fast. I'll share some insight on why we created it, which might help ellucidate why you need it too 🧵 https://twitter.com/vercel/status/1280176016825225216
📰 Next.js started out as a SSR framework

⚛️ Today, it's hybrid: it auto-exports individual pages as pure HTML (when getInitialProps is not used). It also has powerful primitives for static generation

💡 When we first built the Vercel dashboard, we naturally used SSR! However…
🐢 Blocking on all data to be there for each payload felt frustratingly slow.

📖 Furthermore, transitioning between pages had the "turbolink" effect. All clicks were blocked on data fetching. Even the back button!

⚡️ We could do better with Jamstack
💀 We decided to get rid of `getInitialProps` for our dashboard pages, just using HTML skeletons.

💅 All our marketing pages and blogs were switched to `getStaticProps`.

🗺 Vercel became just a bunch of .html, distributed by @vercel automatically at the edge
🤔 The missing piece: how do you load data like the user state? Our teams? Projects, events, deploys, logs?

💭 How do you make it so that all page transitions are snappy like in native apps? How do you make the back button instant, memorizing pagination?

✅ Meet SWR!
SWR is a tiny layer on top of React Hooks, which brings a great deal of automation to managing caches and data that gets re-used throughout your app.

As an example, when you lose your internet connection and re-connect, SWR will re-evaluate the data fetching on the screen.
It's always *eventually correct*. Data can be transitively stale, but the magic of hooks kicks in to re-fetch and bring everything up to speed.

Because it works on top of any async function, this means you get synchronization out of the box for any API backend (REST or GQL!)
Finally, there are some awesome features and improvements yet to be announced.

Follow SWR's creator and maintainer @shuding_ to stay in the loop!
You can follow @rauchg.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: