Is there an API similar to next.js' revalidatePath?
yuumi3 opened this issue · comments
I want to redisplay the screen with the latest data.
No, because we don't cache data at all on the server. (assuming revalidatePath
is to revalidate cache on the server.)
Are you using createPages
API?
We don't (yet) provide to force refetching for the current location.
A workaround for now is to changeLocation without changing location.
I haven't tried if it works. Can you try?
import { useChangeLocation } from 'waku/router/client';
// in a component
const changeLocation = useChangeLocation();
return (
<button onClick={() => changeLocation()}>Refetch</button>
);
One of the reasons I didn't add such an API (yet) is I wasn't sure if the same location can be cached by something outside Waku.
So, thought something like changeLocation(undefined, new URLSearchParams({ t: Date.now() }))
might do.
I'm not very familiar with force refreshing in other frameworks, so suggestions are welcome. cc @sandren
Thank you.
The Refetch button worked once, but it didn't work after the second time.
Thank you very much !
changeLocation(undefined, new URLSearchParams({ t: String(Date.now()) }));
worked
The Refetch button worked once, but it didn't work after the second time.
I see. It's because we cache it on the client. We need some solutions along with designing the api.
glad to hear that the workaround works for now.
It's because we cache it on the client.
#546 fixes it. We no longer need ?t=123
hack with it.