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'm using preload before my react app gets loaded to do an API call that is then also available in the React App for useSWR. If I want to test my preload code I need to invalidate the SWR cache. I cannot currently cannot see a way to do this.
before react app gets started:
constpermissions=awaitpreload<UserPermissions>(PERMISSION_URL,fetcher);if(permissions.foo==="bar"){// do this}else{// do that}
test1:
mockAxios.get.mockResolvedValueOnce({data: {foo: 'bar'},});awaitinit();// will go into the "do this" branch
test2:
mockAxios.get.mockResolvedValueOnce({data: {foo: 'bar2'},});awaitinit();// should go into the "do that" branch but will go into "do this" because SWR is caching the mocked response
How can I invalidate the preload cache from outside of an React app?
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.
-
I'm using
preload
before my react app gets loaded to do an API call that is then also available in the React App foruseSWR
. If I want to test my preload code I need to invalidate the SWR cache. I cannot currently cannot see a way to do this.before react app gets started:
test1:
test2:
How can I invalidate the
preload
cache from outside of an React app?cache
not exported globally +populateCache
not working as expected #2352Beta Was this translation helpful? Give feedback.
All reactions