This repository has been archived by the owner on Mar 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update ShopifyProvider with flattened props (#156)
- Loading branch information
Showing
17 changed files
with
471 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
'@shopify/storefront-kit-react': patch | ||
--- | ||
|
||
`<ShopifyProvider />` and `useShop()` have had a breaking update: | ||
|
||
## `ShopifyProvider` | ||
|
||
- `<ShopifyProvider />` previously accepted a single `shopifyConfig` object as a prop; now, each of the keys in this object are their own separate props. | ||
- We also removed `country` and `language` as objects, and they are now strings with the names `countryIsoCode` and `languageIsoCode`, respectively. | ||
- The `locale` prop has been removed completely; this was a duplicative prop that was a combination of `countryIsoCode` and `languageIsoCode`, so it made no sense to have to include it as well. | ||
|
||
An example: | ||
|
||
```tsx | ||
// previously: | ||
|
||
<ShopifyProvider | ||
shopifyConfig={{ | ||
storeDomain: 'my-store', | ||
storefrontToken: 'abc123', | ||
storefrontApiVersion: '2022-10', | ||
country: { | ||
isoCode: 'CA', | ||
}, | ||
language: { | ||
isoCode: 'EN', | ||
}, | ||
locale: 'EN-CA', | ||
}} | ||
> | ||
{/* rest of your client-side app */} | ||
</ShopifyProvider> | ||
``` | ||
|
||
```tsx | ||
// now | ||
|
||
<ShopifyProvider | ||
storeDomain="my-store" | ||
storefrontToken="abc123" | ||
storefrontApiVersion="2022-10" | ||
countryIsoCode="CA" | ||
languageIsoCode="EN" | ||
> | ||
{/* rest of your client-side app */} | ||
</ShopifyProvider> | ||
``` | ||
|
||
## `useShop()` | ||
|
||
As noted above, `locale` was removed from the `<ShopifyProvider />` component, and `countryIsoCode` and `languageIsoCode` were renamed. Here's an example of how the return value of `useShop()` was affected | ||
|
||
```tsx | ||
// before | ||
|
||
const {country, language, locale} = useShop(); | ||
|
||
console.log(country.isoCode); | ||
console.log(language.isoCode); | ||
console.log(locale); | ||
``` | ||
|
||
```tsx | ||
// after | ||
|
||
const {countryIsoCode, languageIsoCode} = useShop(); | ||
|
||
console.log(countryIsoCode); | ||
console.log(languageIsoCode); | ||
console.log(`${languageIsoCode}-${countryIsoCode}`); | ||
``` | ||
|
||
Note that `locale` can be replicated by combining `languageIsoCode` and `countryIsoCode` with a hypthen (`-`) between them. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
303 changes: 231 additions & 72 deletions
303
packages/react/docs/generated/generated_docs_data.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
import {ShopifyProvider} from '@shopify/storefront-kit-react'; | ||
import {ShopifyProvider, useShop} from '@shopify/storefront-kit-react'; | ||
|
||
export default function App() { | ||
return ( | ||
<ShopifyProvider | ||
shopifyConfig={{ | ||
storeDomain: 'my-store', | ||
storefrontToken: 'abc123', | ||
storefrontApiVersion: '2022-10', | ||
}} | ||
storeDomain="my-store" | ||
storefrontToken="abc123" | ||
storefrontApiVersion="2022-10" | ||
countryIsoCode="CA" | ||
languageIsoCode="EN" | ||
> | ||
{/* rest of your client-side app */} | ||
<UsingUseShop /> | ||
</ShopifyProvider> | ||
); | ||
} | ||
|
||
export function UsingUseShop() { | ||
const shop = useShop(); | ||
|
||
return ( | ||
<> | ||
<div>{shop.storeDomain}</div> | ||
<div>{shop.storefrontToken}</div> | ||
<div>{shop.storefrontApiVersion}</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
import {ShopifyProvider} from '@shopify/storefront-kit-react'; | ||
import {ShopifyProvider, useShop} from '@shopify/storefront-kit-react'; | ||
|
||
export default function App() { | ||
return ( | ||
<ShopifyProvider | ||
shopifyConfig={{ | ||
storeDomain: 'my-store', | ||
storefrontToken: 'abc123', | ||
storefrontApiVersion: '2022-10', | ||
}} | ||
storeDomain="my-store" | ||
storefrontToken="abc123" | ||
storefrontApiVersion="2022-10" | ||
countryIsoCode="CA" | ||
languageIsoCode="EN" | ||
> | ||
{/* rest of your client-side app */} | ||
<UsingUseShop /> | ||
</ShopifyProvider> | ||
); | ||
} | ||
|
||
export function UsingUseShop() { | ||
const shop = useShop(); | ||
|
||
return ( | ||
<> | ||
<div>{shop.storeDomain}</div> | ||
<div>{shop.storefrontToken}</div> | ||
<div>{shop.storefrontApiVersion}</div> | ||
</> | ||
); | ||
} |
Oops, something went wrong.