github vercel/swr 1.2.0-beta.0

latest releases: v2.2.6-beta.2, v2.2.6-beta.1, v2.2.6-beta.0...
pre-release2 years ago

Highlights of This Release

Dedicated API for Optimistic Updates with Auto Rollback on Error

There are now some new options in mutate:

mutate(patchUser(user), {
  optimisticData: user,
  populateCache: true,
  rollbackOnError: true,
  revalidate: true,
})

Here the cache will be immediately updated to user, the “optimistic value”. And then a request (remote mutation) is started via patchUser(user) and the response will be written to the cache. If that request fails, the original result will be rolled back safely so the optimistic value will be gone. And after all those finish, a revalidation will start to fetch the latest value.

This is extremely helpful for building the optimistic UI pattern.

You can do the same for the global mutate, just remember to pass the key. Also, the current mutate APIs stay unchanged so mutate(data, false) works the same.

Here's an example: https://codesandbox.io/s/swr-basic-forked-k5hps.

What's Changed

Full Changelog: 1.1.2...1.2.0-beta.0

Don't miss a new swr release

NewReleases is sending notifications on new releases.