I am facing an issue. I am using Next.js SSR (Server-Side Rendering), and when I run 'npm run dev,' everything works fine. However, when I build Next.js and run 'npm start,' the API response is cached by Next.js. So, when I refresh the page, the response remains exactly the same. I want to receive new data from the API every time I refresh the page.
code
// app.tsx
import React from 'react';
import Joke from '../utils/jokeapi';
const Home = async () => {
const data = await Joke();
console.log('data', data);
return (
<div className="p-5 pt-10">
<h1 className="text-5xl p-5">Welcome Jokes HUB</h1>
{data.map((joke: Joke, index: number) => {
return (
<div key={index} className="p-5">
<h1 className="text-3xl">{joke.joke}</h1>
</div>
);
})}
</div>
);
};
export default Home;
//jokeapi.tsx
import axios from 'axios';
const Joke = async () => {
const Backend = process.env.SERVER || 'http://localhost:3001';
console.log('backend', Backend);
const Response = await axios.get(`${Backend}/api/jokes`);
const jokeData = Response.data;
return jokeData;
};
export default Joke;
I used the 'cache: no-cache' on my Axios, but it's not working. I checked that 'cache: no-cache' with the Fetch API without Axios, and the same thing is not working."