useStreamQueries syntax
- jamesljaworski85OP 1
Hey DAMLer’s.!
I am having trouble interpreting the syntax for writing a query in
jsusing the@daml/reactpackage.Instead of returning all contracts of
Template: IssuanceRequest, I want to return only thoseIssuanceRequestwherestatus="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!
- Stephen
Note that the type of the second argument from the example, which used
useStreamQuery, is() => Query<T>, whereas foruseStreamQueriesas 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.
- jamesljaworski85 2
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"}]), []); - Gary_Verhaegen 1
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?
- jamesljaworski85 3
Hey, @Gary_Verhaegen. The above works now. After building our demo with
SDK 0.13.34it’s pretty sweet to see how awesome the dev tools are now. I am already seeing so many ‘code efficiencies’.