T
TanStack10mo ago
rising-crimson

Pending state after mutation

Is there any way to add a pending state to an element after a mutation with only router or is this a solution that needs react query?
6 Replies
metropolitan-bronze
metropolitan-bronze10mo ago
can you please describe in more detail what you want to do?
rising-crimson
rising-crimsonOP10mo ago
yea absolutely, i have some price data on my page that comes from my loader. I have a selector on the page that allows the user to change the currency, which then sends a request to the server for the new amount in the requested currency. But currently there is a delay in when the user switches and when the new data replaces the amount on the page. I was hoping to show a loading state in place of the old amount while the app waits for the server response. This should be easy to do with a mutation in Query, but I wanted to see if there was a method of doing this purely through Router. After I call router.invalidate() is there any way to see that the data is invalidated so i can show a loading state until the data is refreshed?
metropolitan-bronze
metropolitan-bronze10mo ago
you could check routerState.status
rising-crimson
rising-crimsonOP10mo ago
problem with that is the loading state appears everytime the child route changes. I think i'll implement react query to deal with it
metropolitan-bronze
metropolitan-bronze10mo ago
you can also look into the match status specifically via useMatch
rising-crimson
rising-crimsonOP10mo ago
will look into it, probably just going to add tanstack query thanks

Did you find this page helpful?