You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add item (/add-item): Page with form where you can add new item
Now when I navigate to "Add item" page, fill out the form and submit it, I make POST request to backend so that new item is added to DB. In this case I don't want to wait for the request to finish before navigating back to home page.
Instead I want to navigate to home page right away and optimistically update the list of rendered items with the form data I submitted. And when the request is finished, I want to again use just the real data from loader. How can I do this? Docs only cover how to do optimistic updates on the same page.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Simple use case here, I have two routes/pages:
/home
): Renders a list of items/add-item
): Page with form where you can add new itemNow when I navigate to "Add item" page, fill out the form and submit it, I make POST request to backend so that new item is added to DB. In this case I don't want to wait for the request to finish before navigating back to home page.
Instead I want to navigate to home page right away and optimistically update the list of rendered items with the form data I submitted. And when the request is finished, I want to again use just the real data from loader. How can I do this? Docs only cover how to do optimistic updates on the same page.
Example project (see comments in code): https://stackblitz.com/edit/github-ljo9w9-ujym5o?file=src%2FApp.tsx
So far I have found one workaround where we forget about
action
function andForm
and instead usenavigate
+useLocation
:Kinda hacky or not?
Beta Was this translation helpful? Give feedback.
All reactions