useStreamQueries syntax

Hey DAMLer’s.!

I am having trouble interpreting the syntax for writing a query in js using the @daml/react package.

Instead of returning all contracts of Template: IssuanceRequest, I want to return only those IssuanceRequest where status="Pending". If there are none, don’t want to return anything.

Returns all contracts:
const requests = useStreamQueries(IssuanceRequest)

Attempt to only return those with status=“Pending” using this example from a previous post:
const requests = useStreamQueries(IssuanceRequest, () => ({status: "Pending"}), []);

What’s the best syntax to use to perform a query like this?

Thanks!

1 Like

Note that the type of the second argument from the example, which used useStreamQuery, is () => Query<T>, whereas for useStreamQueries as you use here, the type is () => Query<T>[]. From the documentation for the latter:

A function returning an array of queries.

The lambda you pass as the second argument must then return an array containing your query, rather than a single query.

I’m curious about exactly what TypeScript error you got, if you have that on hand.

Hey @Stephen. I think that was part of my problem. I’m working in JavaScript and don’t haven’t worked in Typescript before. Sometimes I find myself trying to translate from Typescript to Javascript (not a recipe for success when you don’t know Typescript).

I did figure out the mistake I made after finding this documentation. You also pointed out the missing [...] above.

 const requests = useStreamQueries(IssuanceRequest, () => ([{status: "Pending"}]), []);
2 Likes

That last form seems correct to me; can you confirm it now works as expected? If not, would you mind sharing the error message, or describing the unexpected behaviour if there is no error?

1 Like

Hey, @Gary_Verhaegen. The above works now. After building our demo with SDK 0.13.34 it’s pretty sweet to see how awesome the dev tools are now. I am already seeing so many ‘code efficiencies’.

3 Likes