useSWRのoptions
from useSWR
docs
前回メモったときから少し更新されてるっぽいので注意mrsekut.icon*2
suspense
React.Suspenseを使う
initialData
初期値
SSRするときはこれがないとバグるらしい
なぜ #??
refreshInterval
pollingの期間
例えば、refrefhInterval: 1000にすると1s置きにreqを投げる
https://swr.vercel.app/docs/revalidation#revalidate-on-interval
refreshWhenHidden = false: polling when the window is invisible (if refreshInterval is enabled)
dedupingInterval = 2000: dedupe requests with the same key in this time span
focusThrottleInterval
1度だけRevalidateする期間
なぜ1度だけ?
いつ使うの #??
refreshWhenOffline
ブラウザがオフラインのときにpollingする
何に使うの #??
loadingTimeout
タイムアウトする時間
エラー時の処理
shouldRetryOnError
エラー時にリトライするか
errorRetryInterval
リトライするinterval
errorRetryCount
リトライするmaxの回数
5を指定すれば、5回失敗したら、それ以降は最fetchを試みない
onLoadingSlow(key, config)
callback function when a request takes too long to load (see loadingTimeout)
onSuccess(data, key, config)
callback function when a request finishes successfully
onError(err, key, config)
callback function when a request returns an error
onErrorRetry(err, key, config, revalidate, revalidateOps)
error時に再実行する処理を上書きする
defaultでは、Exponential Backoffを使っているらしい
https://qiita.com/irico/items/d8f0ed7887f3c490ffa1#エラーハンドリングについて
compare(a, b)
comparison function used to detect when returned data has changed, to avoid spurious rerenders. By default, dequal is used.
isPaused()
function to detect whether pause revalidations, will ignore fetched data and errors when it returns true. Returns false by default.