#nextjs next tags
1 messages · Page 1 of 1 (latest)
Yes, you can use next: { tags } in a POST method. This is used for caching purposes in Next.js. When you make a fetch request, you can include tags in the options. Later, when some content changes, you can call an API route and pass some tags. This will revalidate the cache for those tags, ensuring that your data is up-to-date.
Here's an example from the extracts:
const req = await fetch(
`${url}/items`,
{ method: 'GET', headers, next: { revalidate: 2, tags: ['items'] } }
);
And here's how you might revalidate the tags:
let tagsRevalidate = tag.split(",");
tagsRevalidate.map(async (tagItem) => {
let urlRevalidate = tagItem;
if (!urlRevalidate) urlRevalidate = "/";
urlRevalidate = urlRevalidate.trim();
revalidateTag(urlRevalidate);
});
This code splits the tags by comma, trims each tag, and then revalidates it. After calling the API with the tags, refreshing the page should show the latest changes.
Please note that this feature might have some issues in certain versions of Next.js, as mentioned in the extracts. If you encounter any problems, you might want to try the latest canary version of Next.js, which includes some fixes related to revalidateTag.
Sources:
- Github Issue (open): Background revalidation does not rerender > Comments Part 2 (https://github.com/vercel/next.js/issues/50606)
- Github Issue (closed): fetch revalidation not working with Nextjs 14.0.0 > Comments Part 8 (https://github.com/vercel/next.js/issues/57632)
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@valid ore kapa.ai is still learning and improving, please let us know how it did by reacting below
Let me check the knowledge base for you. One moment! :books:
Sorry @valid ore, I seem to be having a bit of trouble. Don't worry though, I've pinged my supprt and they will try to fix me up! :technologist:
Perhaps try again in 15mins?
Let me check the knowledge base for you. One moment! :books: