RevalidatePath
Unanswered
Daggertooth pike conger posted this in #help-forum
Daggertooth pike congerOP
Does revalidatePath works in settimeout or not if it does then how can i make it work i am using this code and its not working:
setTimeout(async () => {
const tempBan = await TempModModel.findOne({
GuildID: guildId,
UserID: userId,
Type: "ban",
});
if (tempBan) {
await deleteGuildBanAPI(guildId, userId, reason);
revalidatePath("/");
await tempBan.deleteOne();
}
}, timeInMS);28 Replies
it should work if you are using it in server action or route handler
@Ray how do you use this code?
Daggertooth pike congerOP
what i am doing is making a temp ban function so basically when the user ban it added to the database after that get the time put it in the settimeout and after the time fininsh then unban and revalidate the data so the ui is refreshed
but its not working only in the settimeout otherwise it works
@Daggertooth pike conger what i am doing is making a temp ban function so basically when the user ban it added to the database after that get the time put it in the settimeout and after the time fininsh then unban and revalidate the data so the ui is refreshed
where do you execute that code? could you show more code?
Daggertooth pike congerOP
my codebase is big so i will just tell if you still do not understand i will collect the main parts of the and give you
so basically i have a button in different route (/moderation/users) which opens a modal and then user has to fill the fields after clicking confirm the data revalidate (and it works) and the data is also added in the database with the time given so in the same action Function which banned the user has this settimeout function so then i go to the other page (/moderation/bans) where the temp bans are then the time finishes but the data is not revalidated
@Daggertooth pike conger so basically i have a button in different route (/moderation/users) which opens a modal and then user has to fill the fields after clicking confirm the data revalidate (and it works) and the data is also added in the database with the time given so in the same action Function which banned the user has this settimeout function so then i go to the other page (/moderation/bans) where the temp bans are then the time finishes but the data is not revalidated
so you have the data on
/ and have a button which will open a modal at /moderation/users and there is a form for mutation?@Ray so you have the data on `/` and have a button which will open a modal at `/moderation/users` and there is a form for mutation?
Daggertooth pike congerOP
no the data is on the same
route
@Daggertooth pike conger Click to see attachment
Daggertooth pike congerOP
you got it
on
/moderation/bans?Daggertooth pike congerOP
if not then i havve to go i will check tomorrow
@Ray on `/moderation/bans`?
Daggertooth pike congerOP
then you should
revalidatePath(/dashboard/[id]/moderation/bans)@Ray then you should `revalidatePath(/dashboard/[id]/moderation/bans)`
Daggertooth pike congerOP
i did this also did not worked
have you tried refresh?
Daggertooth pike congerOP
refresh removes it but i want it like auto
I think you need to refresh if you use it inside the setTimeout
Daggertooth pike congerOP
i need to go i will talk later and Thank you for answering
if you use it directly in the server action, it will revalidate when the response come back. Otherwise, it will only happens on the next visited
in this case, I think its better to do client side fetching with a interval
Daggertooth pike congerOP
Hello i am back
so like now what i have to do use "useRouter" and also the settimeout is in the Actions nnot in the client mode
is there anny other way we can refresh the data in server actions?
@Daggertooth pike conger is there anny other way we can refresh the data in server actions?
we can revalidate the data and get the data updated with server action but not in a setTimeout
@Ray we can revalidate the data and get the data updated with server action but not in a setTimeout
Daggertooth pike congerOP
yea thats the problem is there any other way which we can do