Client side value update using SWR, not working when deploying to vercel
Answered
Brittany posted this in #help-forum
BrittanyOP
import useSWR from 'swr'
export function usePlayersOnline() {
const { data, isLoading, error } = useSWR('/api/playersHistory/latest', async (...args) => {
return fetch(...args).then(res => res.json())
})
return { quantity: data?.quantity, isLoading, error }
}
Code not working when deployed, but on dev enviroment works fine.
Answered by Brittany
Problem fixed, had to include
export const dynamic = 'force-dynamic' on the route, it was caching data.9 Replies
BrittanyOP
Just to point some things that I've tried, I inserted "use client" and didn't work
BrittanyOP
I inserted one console.log and the data is being cached, always the same res
BrittanyOP
Tried "no-store" on fetch, didn't work
BrittanyOP
Also tried export const dynamic = 'force-dynamic' and nothing happened
BrittanyOP
Tried removing async, and didn't work
BrittanyOP
Tried using fetcher outside the useSWR and nothing happened
BrittanyOP
Tried to use the function inside a page in client side, don't work too
Tried even using just fetch, and nothing is working
BrittanyOP
Problem fixed, had to include
export const dynamic = 'force-dynamic' on the route, it was caching data.Answer