React Hooks for Data Fetching
Checkout subscription docs and useSWRInfinite parallel fetching docs for more details
Full Changelog: https://github.com/vercel/swr/compare/v2.0.4...v2.1.0
Full Changelog: https://github.com/vercel/swr/compare/v2.0.3...v2.0.4
-
characters in README.md by @JanKaifer in https://github.com/vercel/swr/pull/2334
Full Changelog: https://github.com/vercel/swr/compare/v2.0.2...v2.0.3
Full Changelog: https://github.com/vercel/swr/compare/v2.0.1...v2.0.2
In this patch release, we majorly improved typing support and SWR can infer the types based on the configuration.
suspense
option is true
, the returned data
will exclude undefined
and the isLoading
will always be false
.fallbackData
option is provided, the returned data
will be the same type of fallbackData
, and the isLoading
will always be false
.Here's a demo for it:
https://user-images.githubusercontent.com/4800338/213288879-ffbeeeb5-aca5-4a65-8229-69fbf9b0bf70.mp4
Full Changelog: https://github.com/vercel/swr/compare/2.0.0...v2.0.1
We are excited to announce the release of SWR 2.0! The new version comes with a lot of improvements:
And more!
Read our blog post and migration guide: https://swr.vercel.app/blog/swr-v2
isLoading
state and refactor the core by @shuding in https://github.com/vercel/swr/pull/1928
keepPreviousData
option by @shuding in https://github.com/vercel/swr/pull/1929
throwOnError
option by @shuding in https://github.com/vercel/swr/pull/2182
Full Changelog: https://github.com/vercel/swr/compare/1.2.2...2.0.0
Full Changelog: https://github.com/vercel/swr/compare/2.0.0-rc.1...2.0.0-rc.3
The last RC before SWR 2.0. This release includes several small fixes with one breaking change.
In this release, we are dropping IE 11 support, and using ES2018 as the build target. However, when using SWR in a framework or using a bundler (esbuild, Webpack, etc.), you can still target ES5 or using a browserlist configuration to customize this.
The benefit of this change is, we can now use faster native APIs to make SWR more performant, instead of using old alternatives. A benchmark shows a 4.7x speed improvement of the useSWR()
function call during SSR, when we change Object.assign({}, a, b)
to { ...a, ...b }
.
Details can be found in #2249.
Full Changelog: https://github.com/vercel/swr/compare/2.0.0-rc.0...2.0.0-rc.1
The SWR 2.0 release candidate. This RC has one breaking change, a new option for mutation APIs, and some bug fixes & improvements.
A failed mutation will not cause useSWR
's error
to be updated:
const { error, mutate } = useSWR('/api/user', getUser)
return <button onClick={async () => {
try {
await mutate(updateUser)
} catch (mutationError) {
// `mutationError` will not cause `error` to be updated.
}
}}>Update User</button>
In 2.0, with the example above, error
will only be coming from getUser
and will be shared across all useSWR('/api/user')
hooks. And mutation errors (mutationError
) will be coming from mutations like updateUser
calls, they will be separated from fetcher errors.
There is also a new option throwOnError
for useSWRMutation
to disable the default throwing behavior of trigger
:
const { trigger } = useSWRMutation('/api/user', updateUser)
try {
await trigger()
} catch (err) {
// ... it throws when failed to trigger the mutation so you can
// easily change the flow here
}
const { trigger, error } = useSWRMutation('/api/user', updateUser, {
throwOnError: false
})
// You don't need to try-catch here, you can instead handle errors
// on the component level in a declarative way
await trigger()
Read more about this change in #2182.
throwOnError
option by @shuding in https://github.com/vercel/swr/pull/2182
Full Changelog: https://github.com/vercel/swr/compare/2.0.0-beta.7...2.0.0-rc.0
Most changes in this release are maintenance related, as we are finalizing everything for the upcoming 2.0 stable version.
Full Changelog: https://github.com/vercel/swr/compare/2.0.0-beta.6...2.0.0-beta.7