thetrevorharmon / gatsby-theme-shopify-manager

The easiest way to start a Shopify shop on Gatsby.
https://gatsby-theme-shopify-manager.netlify.app/
MIT License
121 stars 11 forks source link

Refresh the cart object on initial load #31

Closed thetrevorharmon closed 4 years ago

thetrevorharmon commented 4 years ago

This PR resolves https://github.com/thetrevorharmon/gatsby-theme-shopify-core/issues/20 by changing the initial loading step within context provider. When an initial cart object is found, it uses the fetch function to refresh the cart with the latest data from Shopify.

As a result, there is one extra render. To account for this, renderHookWithContext takes this into account and waits one tick. There is also renderHookWithContextSynchronously which does not wait a tick.