#First DataStore.query() call is always undefined?

1 messages · Page 1 of 1 (latest)

harsh ether
#

I have a useEffect hook which will call DataStore.query() on a Bucket model with a few parameters. On the first page load in a browser, it will always return undefined, even though the data exists. If I refresh the page, it will properly return the object I'm expecting, every time.

The only solution I've tried said to use the Hub.listener() to listen to datastore and only load the page containing the DataStore.query() useEffect hook once the datastore is ready, but that hasn't resolved my issue.

harsh ether
#

I'm reading the whitepapers (https://docs.aws.amazon.com/pdfs/whitepapers/latest/amplify-datastore-implementation/amplify-datastore-implementation.pdf) and I see this, which I think explains the problem...but I'd like to know a solution

If cloud sync is enabled, at the first application start, the Sync Engine will run a GraphQL query that populates the Storage Engine from the network using a base query, which is the Sync Engine’s most basic form of synchronization that retrieves the baseline state of your records. This will replicate the current state of your backend with your client application.