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
Our application uses onSuccess to trigger certain desired behavior. However, in testing, it appears that onSuccess is only triggered if that specific useSWR call is responsible for the success - if the data was already loaded from another useSWR call, it's not triggered.
Expected Behavior
onSuccess is triggered whenever data is successfully available, whether that successful request came from this instance or another.
This is currently a expected behavior since SWR will deduplicate the requests so only one request will be executed and trigger the onSuccess callback once. #1580
You could use useEffect as alternative.
const{ data }=useSWR('api',fetcher)React.useEffect(()=>{if(data)//do something}},[data])
This is currently a expected behavior since SWR will deduplicate the requests so only one request will be executed and trigger the onSuccess callback once. #1580
You could use useEffect as alternative.
const{ data }=useSWR('api',fetcher)React.useEffect(()=>{if(data)//do something}},[data])
Is it guaranteed that the data object reference will be the same between renders so that hook doesn't get executed until there's a new request (for example when using immutable swr hooks)?
Bug report
Description / Observed Behavior
Our application uses
onSuccess
to trigger certain desired behavior. However, in testing, it appears thatonSuccess
is only triggered if that specificuseSWR
call is responsible for the success - if the data was already loaded from anotheruseSWR
call, it's not triggered.Expected Behavior
onSuccess
is triggered whenever data is successfully available, whether that successful request came from this instance or another.Repro Steps / Code Example
https://codesandbox.io/s/swr-on-success-uuigol?file=/src/App.tsx
Additional Context
SWR version: 2.1.1
The text was updated successfully, but these errors were encountered: