I am building a Next.js app with wordpress headless cms that is static built with the revalidation functionality, and deployed on aws amplify, However, when i make a change in my wordpress, it toggles between the lastest data and previous data each time i refresh.
Here is my function below, i expect that when i refresh my page after 2 seconds, it should give me the latest data without toggling with the previous data.
export async function fetchAPI(query = "", { variables } = {}) {
const res = await fetch(process.env.NEXT_PUBLIC_WORDPRESS_API_ENDPOINT, {
method: "post",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
query,
variables,
}),
next: { revalidate: 2 },
});
if (!res.ok) {
console.error(res);
return {};
}
const { data } = await res.json();
return data;
}