Next.js Discord

Discord Forum

Next.js and webhooks vs polling

Unanswered
Bonga shad posted this in #help-forum
Open in Discord
Bonga shadOP
I am implementing a video upload functionality. I have an entity "A" for which I want to upload the video. I want to return a status "ok" to indicate that the video upload has been initiated, but I also want to refetch this entity once the upload is successfully completed. I am using React Query, but calling refetch or invalidating the query on success won't work, as the upload takes a few seconds.

What is the best approach in Next.js? I have flexibility in how to implement this, but I am aiming for an efficient solution, i.e., minimizing API calls and avoiding unnecessary re-renders.

Is it better to create a webhook or just a separate endpoint to check the status of the upload and refetch the entity upon successful upload?

1 Reply

Chub mackerel
why not just use react query to poll the status endpoint? you can set an interval on the useQuery hook