Replies: 1 comment
-
|
you can do imperative queries with |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Imperative Query in a Non-Linear Wizard Form
Hello all,
// First... our package.json
{ ... "react": "18.3.1", ... "@tanstack/react-query": "^5.85.9", ... }We’re in a tricky spot with an imperative query. I came across this discussion by @TkDodo and this #1546, but our case is a little different.
We have a multi-step wizard form that’s not linear. It behaves more like a tree. The next form step depends on data from our backend.
Each step has a Next button, and based on some heavy logic (that cannot live in the frontend), the backend decides where the user should go.
Here’s a simplified pseudo-code example:
Since the backend isn’t mutating anything and only returns the next step, it’s exposed as a
GETendpoint.Naturally, our first instinct is to use
useQueryfor GET requests, but in this case, we’re unsure what’s best.Here are the options we’re considering:
Option 1:
useQueryPros
Cons
onSubmit.Option 2:
useMutationPros
api.getNext.Cons
Option 3:
useMutationjust as option 2 but change the names not to confuse developersPros
Cons
nextGetImperative.mutate, which can confuse devsOption 4: Don’t Use TanStack Query
Pros
Cons
The Question
Given that:
onSubmitflow.👉 Which approach makes the most sense here?
👉 any other approach we are not thinking about or don't know about?
Thanks!!!
PS: We are aware of TanStack DB but, right now it's not possible for us to give it a try
Beta Was this translation helpful? Give feedback.
All reactions