Bot releases are hidden (Show)
Published by shuding almost 3 years ago
Full Changelog: https://github.com/vercel/swr/compare/1.1.2...1.2.0-beta.1
Published by shuding almost 3 years ago
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.
Full Changelog: https://github.com/vercel/swr/compare/1.1.2...1.2.0-beta.0
Published by shuding almost 3 years ago
SWR will now use the latest fetcher function passed to the hook, when sending the request. Previously it uses the initial snapshotted fetcher.
When refocusing on the window with state changes (like clicking a button that changes the SWR key immediately), SWR now avoids revalidations if they're not necessary. Details can be found in #1720.
useSWRInfinite
Two types for useSWRInfinite
are added: SWRInfinteHook
and SWRInfinteKeyLoader
. You can use them to type the hook and the getKey
function.
populateCache
option for mutate
A new option to control if the mutation data should be written to the cache. You can find the details in #1729.
requestAnimationFrame
more robust by @thomaspaulmann in https://github.com/vercel/swr/pull/1707
populateCache
option to mutate
by @shuding in https://github.com/vercel/swr/pull/1729
Full Changelog: https://github.com/vercel/swr/compare/1.1.1...1.1.2
Published by shuding almost 3 years ago
We now have 23 test suits of 202 total test cases, with a 98.06% test coverage. The core files and main functionalities are now 100% covered. Kudos to @promer94 for improving it!
SWR will now use the latest fetcher function passed to the hook, when sending the request. Previously it uses the initial snapshotted fetcher.
When refocusing on the window with state changes (like clicking a button that changes the SWR key immediately), SWR now avoids revalidations if they're not necessary. Details can be found in #1720.
useSWRInfinite
Two types for useSWRInfinite
are added: SWRInfinteHook
and SWRInfinteKeyLoader
. You can use them to type the hook and the getKey
function.
Full Changelog: https://github.com/vercel/swr/compare/1.1.2-beta.0...1.1.2-beta.1
Published by shuding almost 3 years ago
requestAnimationFrame
more robust by @thomaspaulmann in https://github.com/vercel/swr/pull/1707
Full Changelog: https://github.com/vercel/swr/compare/1.1.1...1.1.2-beta.0
Published by shuding almost 3 years ago
refreshInterval
You can now pass a function as refreshInterval
, to dynamically return the interval (in millisecond) til the next request, based on the current data:
useSWR('key', fetcher, {
refreshInterval: function (data: Data | undefined) {
if (!data) return 3000 // Initial request
return data.next_update
}
})
If return 0
, polling will be stopped.
newData
is deeply to the latest state, broadcast the latest state by @icyJoseph in https://github.com/vercel/swr/pull/1697
undefined
data if key's falsy under suspense mode by @icyJoseph in https://github.com/vercel/swr/pull/1698
Full Changelog: https://github.com/vercel/swr/compare/1.1.0...1.1.1
Published by shuding almost 3 years ago
useSWR({ query: graphql`...`, variables }, fetcher)
useSWR({ query: graphql`...`, variables }, fetcher)
useSWR({ variables, query: graphql`...` }, fetcher)
// ^all recognized as the same resource
For array keys too, it's safe to do the following:
useSWR([ `...`, { variables } ], fetcher)
revalidateFirstPage
for useSWRInfinite
This is a new added option for useSWRInfinite
(defaults to true
), you can use it to control if the first page should be revalidated when changing the size or doing a mutation.
axios
with fetch interceptor by @danestves in https://github.com/vercel/swr/pull/1548
type: "module"
and use .mjs
extension by @shuding in https://github.com/vercel/swr/pull/1604
getKey
in useSWRInfinite
by @shuding in https://github.com/vercel/swr/pull/1681
Full Changelog: https://github.com/vercel/swr/compare/1.0.1...1.1.0
Huge thanks to @TakahiroHimi, @morgs32, @aFINKndreas, @zhaomengfan, and @junsushin-dev for helping!
axios
with fetch interceptor: #1548Huge thanks to @danestves and @huozhi for helping!
Huge thanks to @timas130 and @huozhi for helping!
Huge thanks to @huozhi and @promer94 for helping!
Huge thanks to @promer94 and @huozhi for helping!
Huge thanks to @huozhi and @koba04 for helping!
Huge thanks to @huozhi, @koba04, @anirudh1713, @anothertempore, and @amannn for helping!