Next.js Discord

Discord Forum

Best approach to rehydrate a ui

Answered
Pigeon tremex posted this in #help-forum
Open in Discord
Pigeon tremexOP
In react what’s the best approach, to rehydrate the ui e.g button that fetches an api to delete a product, and show them the updated ui,

Right now after the delete request, I’m have rewritten a fetch request to get the product and updated the use state
Answered by fuma
You can actually return something from your delete request, therefore, you don't need to send another fetch request
And there're many ways to display the deleted items on your UI, like modals, lists, or redirecting users to another page. Both of them are good approach, a "best approach" doesn't exist
View full answer

6 Replies

Not sure what you mean by "rehydrate", Next.js hydrates client components and it's irrelevant to your question
Do you mean by re-render?
You can actually return something from your delete request, therefore, you don't need to send another fetch request
And there're many ways to display the deleted items on your UI, like modals, lists, or redirecting users to another page. Both of them are good approach, a "best approach" doesn't exist
Answer
In you case, updating state is great enough
@fuma In you case, updating state is great enough
Pigeon tremexOP
Honeslty it didnt feel right writing fetch request for the items after a delete fetch request(edit fetch request ext ), felt there away to rerender a table ext