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
Previously shouldRetryOnError is either true or false. Now it accepts a function that conditionally determines if SWR should retry. Here's a simple example:
constfetcher=url=>fetch(url).then(res=>{// Fetcher throws if the response code is not 2xx.if(!res.ok)throwresreturnres.json()})useSWR(key,fetcher,{shouldRetryOnError: (error)=>{// We skip retrying if the API is returning 404:if(error.status===404)returnfalsereturntrue}})
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
Uh oh!
There was an error while loading. Please reload this page.
-
Highlights of This Release
shouldRetryOnError
accepts a functionPreviously
shouldRetryOnError
is either true or false. Now it accepts a function that conditionally determines if SWR should retry. Here's a simple example:Thanks to @sairajchouhan for contributing!
What's Changed
shouldRetryOnError
accepts a function that can be used to conditionally stop retrying by @sairajchouhan inshouldRetryOnError
accepts a function that can be used to conditionally stop retrying #1816New Contributors
shouldRetryOnError
accepts a function that can be used to conditionally stop retrying #1816Full Changelog: 1.2.0...1.2.1
This discussion was created from the release 1.2.1.
Beta Was this translation helpful? Give feedback.
All reactions