Question about the behavior of react hooks (useStreamQuery in particular)
- DarkoOP
Assume that the result of a query would be 50 elements long.
If you use that query inuseStreamQueryand leverage that output in a component, you are going to get 50 (51?) redraws of that component, as the result will be
[]then[elem1], then[elem1, elem2], …, then[elem1, ..., elem50]and so on.- Is the above correct? (our investigations seem to indicate that, but I’d still rather double-check)
- Is the example above expected behavior?
- If so, why?
My expectation would be that after calling
useStreamQueryI would- get the current state,
- get updates on future state changes.
- cocreature
Your investigation is almost correct. The ACS at the beginning of a stream query is delivered as a stream of
CreateEventarrays. We don’t make any guarantees on those arrays being singletons. I believe atm you get one per transaction so if your contracts got created as part of separate transactions you’ll see the behavior you describe. If some are part of the same transaction, you might see multiple contracts being added as part of one change.useStreamQueryprovides aloadingfield on the result in addition to thecontractsfield. This istrueuntil the ACS query has completed and we are working with full ACS snapshots. If you don’t want to draw partial results, you can wait untilloadingis false before you display anything in your render function. However, it is often nicer to start with partial results and update them as you receive more.