starknet-react icon indicating copy to clipboard operation
starknet-react copied to clipboard

`useStarknetCall` set `loading` to `false` before the data is actually loaded

Open ltoussaint opened this issue 3 years ago • 0 comments

In the useEffect of the useStarknetCall hook, we call dispatch({ type: 'set_last_updated_at', blockHash: block.block_hash }) without waiting the refresh to finalize. Which leads to set loading (and maybe lastUpdatedAt) to early.

https://github.com/apibara/starknet-react/blob/883cba7b7188201ab27baccf75f3569a3eec4cc3/packages/core/src/hooks/call.ts#L119-L120

  • In think we should only allow the dispatch types set_call_response and set_call_error to be able to set the loading property.
  • Also, maybe we should only set the lastUpdatedAt property when the new data are loaded properly.

ltoussaint avatar Jul 07 '22 13:07 ltoussaint