Server component - send a request every hour+
Unanswered
Cane Corso posted this in #help-forum
Cane CorsoOP
Hey i got this server side component:
how can i run the axios.get function/fetch every hour or more?
im using
thanks!
import axios from 'axios'
import UpdateButtonClient from './Client'
export const dynamic = 'force-dynamic'
const UpdateButton = async () => {
const tags = await axios.get('https://api.github.com/repos/ShiNxz/CSS-Panel/tags')
console.log(tags.data[0].name)
if (!tags || !tags.data) return <UpdateButtonClient />
const latestVersion = tags.data[0].name as string
const currentVersion = process.env.version as string
return latestVersion !== currentVersion && <UpdateButtonClient />
}
export default UpdateButtonhow can i run the axios.get function/fetch every hour or more?
im using
force-dynamic cause without it it runs only on every build but now its sending it every time someone sees this component which is not what i want either.thanks!
5 Replies
Standard Chinchilla
export const revalidate = 3600
This will tell next js to refresh if a call has been set over 3600 seconds which is 1h
@Standard Chinchilla export const revalidate = 3600
Cane CorsoOP
it works with axios and force-dynamic?
Standard Chinchilla
force dynamic will make it fetch every time the user calls the api
You want to be using revalidate instead