You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Highlights of This Release
Optimistic Updates with Auto Error Rollback
There are now some new options in
mutate
:Here the cache will be immediately updated to
user
, the “optimistic value”. And then a request (remote mutation) is started viapatchUser(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 currentmutate
APIs stay unchanged somutate(data, false)
works the same.Here's an example: https://codesandbox.io/s/swr-basic-forked-k5hps.
CleanShot.2022-01-27.at.15.39.58.mp4
.mjs
SupportSWR now has
.mjs
exported for bundlers that prefer this format.This doesn’t break environments that don’t support
.mjs
. An alternative.esm.js
and CJS bundle are also published.You can read more about ES modules here.
What's Changed
New Contributors
Full Changelog: 1.1.2...1.2.0
This discussion was created from the release 1.2.0.
Beta Was this translation helpful? Give feedback.
All reactions