Next.js Discord

Discord Forum

next.js client cache and supabase rpc calls

Unanswered
Knopper gall posted this in #help-forum
Open in Discord
Avatar
Knopper gallOP
Hi, I have a bit of a dilemma, Im sending some data to Supabase and then fetching a view based on an rpc call. Im sending the data from a client component, and Im using a context hook in the middle to proxy my calls to a server action thats Inserting the data and another method for fetching via rpc.

My issue is the data i store is not available back in the client component because of caching, so in the context hook I call router.refresh and this gets me the latest data, only this messes with my useOptimistic hook which loses state and for a brief moment I have a flash in my UI.

Has anyone got any advice on how to always get back fresh data to the client component via the rpc call. FYI I have also tested this server side and it works fine, my issue is useOptimistic requires a client component.

Thanks!

0 Replies