SDK Reference 4.x
The React can be installed via a Gatsby theme. It's available as an npm package, @chordcommerce/gatsby-theme-autonomy, via GitHub Packages.
Despite the name, this package does not provide a visual theme. To quote from the Gatsby documentation:
Gatsby themes are plugins that include a gatsby-config.js file and add pre-configured functionality, data sourcing, and/or UI code to Gatsby sites. You can think of Gatsby themes as separate Gatsby sites that can be put together and allow you to split up a larger Gatsby project!
gatsby-theme-autonomy includes the React, a set of React hooks that offer an easy way to interact with Chord's order management system, for common operations like adding items to a cart. These hooks provide access to SDK methods that handle communication with Chord's order management system and keep the site's Redux state up to date. They also automatically send tracking events to Segment.
The theme also pre-configures your Gatsby site with a number of useful ecommerce features like sitemaps and internationalization support.
This theme uses a significant amount of Gatsby plugins and transformers. We provide these as peer dependencies instead of vendoring them so that you can upgrade them at your own pace. A couple of major things to keep in mind as you upgrade them:
- First party Gatsby plugins and Gatsby itself should have the same minor version to ensure they are compatible (if you are on the current release of Gatsby). For example, we have [email protected], [email protected] and [email protected]. Note that all of them share a minor version of 13 while the major and patch versions differ. This isn't a hard and fast rule but something that you should strive to maintain where possible.
- gatsby-plugin-sharp and gatsby-transformer-sharp must be the same version. This is because they bundle a binary that having multiple versions of will break builds.
After installing the package, add the following configuration to your gatsby-config.js file:
Run your site as usual, using yarn start.
Hook | Description |
Provides support for sending UI-related tracking events to Segment. | |
useAuth | Provides support for user authentication. Chord supports passwordless authentication with Magic. |
useCart | Returns the current shopping cart, and functions for creating and interacting with the shopping cart. |
Provides support for checkout. | |
Provides support for interacting with products. | |
Provides support for managing user subscriptions. | |
Returns the current user's subscriptions. | |
Provides support for internationalization | |
useUser | Returns the current user, and functions for loading data about the user. |