Next.js Discord

Discord Forum

Revalidate tag in useState

Unanswered
Pixiebob posted this in #help-forum
Open in Discord
Avatar
PixiebobOP
I tried to revalidate a tag after the user successfully submitted the form to immediately update the data. I stored the current data in useState, but since the server is revalidated, the state doesn't update automatically. As a result, I had to use useEffect. Does anyone know how to update the data with the revalidate tag without using useEffect?
Image
Image

1 Reply

Avatar
Tomistoma
As far as I know, revalidateTag only works to purge the cache and change anything on the UI, hence it doesn't trigger a re-render to get an immediate feedback. Using useEffect solves the issue for you because when the initialData changes, you set the new state.

You may check using revalidatePath instead or check out either SWR or React Query.