Best way to "trigger" mutation on Page Load?
I have a 1 SPA page orderform.
1) User navigates with some query parameters (IDs)
2) As soon as page loads I need to raise a POST request to create the initial order draft.
Any recommendation?
I know it's not the best way, but the business works like that. I need to raise a POST request on page load.
I really appreciate your ideas, thanks
2 Replies
equal-aqua•10mo ago
Depending on what routing you're using, probably the route loader
xenial-blackOP•10mo ago
I'm using tanstack router
It's a bit tricky because I need to handle 3 cases.
@troywoy my url it's like this app.com?internetId=1&mobileId=2 . I can permute 3 different cases. Orders for just mobiles (I can do the mutation in the loaders) . Orders for internet OR bundles(internet + mobile) I will need to make another request before creating the order
Probably I'll have to abstract all of this logic and put it on the loader, because it's critical, users cant continue the process if any of these calls fails and to continue the process they need the order id and token for the next calls
@TkDodo 🔮 sorry for tagging you. Do you recommend me to do all of this in the loader?