1

I have a component with a list of conversations and i want to load a specific conversation on click. The problem is that I have to initialise the second trpc query at mount and I dont have the required data yet. Any help would be highly apriciated.

1 Answers1

1

You need to use the enabled flag of useQuery:

const requiredDataIsAvailable = false

trpc.useQuery(['todos'], {
  // query will only fetch data if the following variable evaluates to true
  enabled: requiredDataIsAvailable,
})

Only if enabled is true (= you got the required data for the query), it will fetch the data from the server.

Docs:

Alp
  • 29,274
  • 27
  • 120
  • 198