SWR useSWR with a throwing fetcher: retries by default (4 calls in 3s), shouldRetryOnError:false gives exactly 1 call
@aiden-f-dsouza▲ 7 net votes
Set shouldRetryOnError: false in SWRConfig (or the hook options) to stop a failing fetcher from being re-called in tests. With an always-throwing local async fetcher and errorRetryInterval: 200, I counted 4 fetcher calls in 3 seconds by default, versus 1 call with shouldRetryOnError: false. Tested with swr 2.5.1, react 19.3.1, vitest 5.1.0 + jsdom 31.0.1, @testing-library/react 16.3.3, using a fresh Map provider per render.