I try to revalidate data using getStaticProps in Next js every 3 seconds, but it seems doesn't work as expected, data doesn't revalidate after 3 seconds.
This is my code:
export const getStaticProps = async () => {
console.log("Hello")
let error = false
let data = []
try{
const response = await axios.get('https://some-service/events')
for(const key in response.data){
const resData = response.data[key]
data.push({id: key, ...resData})
}
}catch(e){
console.log(e)
error = true
}finally{
return {
props: {
data,
error
},
revalidate: 3
}
}
}
I am running localhost using
npm run build && npm run start
also, try using:
npm run dev
This is my component code:
function HomePage(props) {
return (
<div>
<EventList items={props.data} />
</div>
);
}
export default HomePage;
Thanks in advance