Next.js Discord

Discord Forum

Invalidate ORM

Unanswered
Serbian Hound posted this in #help-forum
Open in Discord
Serbian HoundOP
So I have a simple component:
export default async function NoteTable() {
    const covers = await Cover.findAll();
    const coverAttributes = covers.map(c => c.dataValues);
    return <PlainTable data={coverAttributes} />
}


I have another button that changes these notes on the DB. But how would I re-render this NoteTable? I read about invalidation here https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#on-demand-revalidation but it looks like I need an API route and then a fetch with the tag, is there any way to do it how I've done it and just associate a tag to that Cover.findAll()?

thanks

4 Replies

Serbian HoundOP
Hmm, to make matters more annoying, I changed it to an API route and used fetch with the tags. It doesn't revalidate the component 😦
 const response = await fetch("http://localhost:3000/api/cover", {
        next: {
            tags: ["cover"]
        },
    });
Solved the above by marking the API route "use server" - but I wish this could be done without resorting to an API route
Serbian HoundOP
in fact it doesn't work..it works very rarely