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
I have a hook that should conditionally fetch some data, when a user logs in.
For that I use a conditional key:
exportfunctionuseWatchlist(){const{ session, fetch }=useSession()constselectedPharmacy=useSelectedPharmacy()const{
data,
error,}=useSWR(session?.userId// DEV-1837: include selected pharmacy to invalidate cache key when pharmacy is changed
? ["/user/watchlist",session.id,selectedPharmacy]
: null,(href)=>fetch({method: "GET", href }))console.log("session & user",session?.id,session?.userId)...}
However, sometimes, while the log has several lines with (same) session and user id filled useSWR never starts the fetch. I see like 40 log lines but not one time a fetch request performed (also logged).
Could that be a debounce problem? Too many updates flooding the hook?
At the start of the program session is undefined therefore the key is null. But this seems to work on almost all other places I use this pattern.
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
-
I have a hook that should conditionally fetch some data, when a user logs in.
For that I use a conditional key:
However, sometimes, while the log has several lines with (same) session and user id filled
useSWR
never starts the fetch. I see like 40 log lines but not one time a fetch request performed (also logged).Could that be a debounce problem? Too many updates flooding the hook?
At the start of the program session is
undefined
therefore the key isnull
. But this seems to work on almost all other places I use this pattern.Beta Was this translation helpful? Give feedback.
All reactions