Shopify / storefront-api-examples

Example custom storefront applications built on Shopify's Storefront API
https://help.shopify.com/api/storefront-api
MIT License
1.12k stars 329 forks source link

Created storefront API example using React and Redux for JavaScript Buy SDK #124

Closed mikeq1225 closed 4 years ago

mikeq1225 commented 4 years ago

I wanted to create a react example that would be easily scalable.

My solution was to create a working example by refactoring the React-JS-Buy example that rewrites the components to be functional components in stead of class based components.
I added Redux to create a store that is accessible throughout the app.

I added the folder reactHooks-redux-js-buy with my files as to not replace the originals in case anyone needs to reference those.

Let me know if there is anything that I need to change.

Thanks.

swalkinshaw commented 4 years ago

Thanks @mikeq1225

I got some warnings while running it. Does these matter?

Compiled with warnings.

./src/components/Products.js
  Line 10:5:  React Hook useEffect has a missing dependency: 'fetchProducts'. Either include it or remove the dependency array  react-hooks/exhaustive-deps

./src/components/App.js
  Line 22:5:  React Hook useEffect has missing dependencies: 'createCheckout', 'createShop', and 'fetchProducts'. Either include them or remove the dependency array  react-hooks/exhaustive-deps

./src/components/ProductView.js
  Line 40:5:  React Hook useEffect has a missing dependency: 'fetchProduct'. Either include it or remove the dependency array  react-hooks/exhaustive-deps

./src/components/Cart.js
  Line 53:5:  React Hook useEffect has a missing dependency: 'getCount'. Either include it or remove the dependency array  react-hooks/exhaustive-deps

Otherwise, it appears to be working well đź‘Ť

mikeq1225 commented 4 years ago

@swalkinshaw

I don't think the warnings matter.
I got these from the React Docs:

All of the functions that are triggering this warning are coming from functions that are outside of the component. They are all in redux/ducks/shopify index.js. Therefore they don't reference props, component state or values, and the function shouldn't change.

Thanks for the question.

swalkinshaw commented 4 years ago

Sounds good, thanks đź‘Ť