-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
93 additions
and
91 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
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
17 changes: 10 additions & 7 deletions
17
.../product/useOptimisticProduct.example.jsx → .../product/useOptimisticVariant.example.jsx
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,22 +1,25 @@ | ||
import {useLoaderData} from '@remix-run/react'; | ||
import {defer} from '@remix-run/server-runtime'; | ||
import {useOptimisticProduct} from '@shopify/hydrogen'; | ||
import {useOptimisticVariant} from '@shopify/hydrogen'; | ||
|
||
export async function loader({context}) { | ||
return defer({ | ||
product: await context.storefront.query('/** product query **/'), | ||
// Note that variants does not need to be awaited to be used by `useOptimisticProduct` | ||
// Note that variants does not need to be awaited to be used by `useOptimisticVariant` | ||
variants: context.storefront.query('/** variants query **/'), | ||
}); | ||
} | ||
|
||
function Product() { | ||
const {product: originalProduct, variants} = useLoaderData(); | ||
const {product, variants} = useLoaderData(); | ||
|
||
// The product.selectedVariant optimistically changed during a page | ||
// transition with one of the preloaded product variants | ||
const product = useOptimisticProduct(originalProduct, variants); | ||
// The selectedVariant optimistically changes during page | ||
// transitions with one of the preloaded product variants | ||
const selectedVariant = useOptimisticVariant( | ||
product.selectedVariant, | ||
variants, | ||
); | ||
|
||
// @ts-ignore | ||
return <ProductMain product={product} />; | ||
return <ProductMain selectedVariant={selectedVariant} />; | ||
} |
17 changes: 10 additions & 7 deletions
17
.../product/useOptimisticProduct.example.tsx → .../product/useOptimisticVariant.example.tsx
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,22 +1,25 @@ | ||
import {useLoaderData} from '@remix-run/react'; | ||
import {defer, LoaderFunctionArgs} from '@remix-run/server-runtime'; | ||
import {useOptimisticProduct} from '@shopify/hydrogen'; | ||
import {useOptimisticVariant} from '@shopify/hydrogen'; | ||
|
||
export async function loader({context}: LoaderFunctionArgs) { | ||
return defer({ | ||
product: await context.storefront.query('/** product query */'), | ||
// Note that variants does not need to be awaited to be used by `useOptimisticProduct` | ||
// Note that variants does not need to be awaited to be used by `useOptimisticVariant` | ||
variants: context.storefront.query('/** variants query */'), | ||
}); | ||
} | ||
|
||
function Product() { | ||
const {product: originalProduct, variants} = useLoaderData<typeof loader>(); | ||
const {product, variants} = useLoaderData<typeof loader>(); | ||
|
||
// The product.selectedVariant optimistically changed during a page | ||
// transition with one of the preloaded product variants | ||
const product = useOptimisticProduct(originalProduct, variants); | ||
// The selectedVariant optimistically changes during page | ||
// transitions with one of the preloaded product variants | ||
const selectedVariant = useOptimisticVariant( | ||
product.selectedVariant, | ||
variants, | ||
); | ||
|
||
// @ts-ignore | ||
return <ProductMain product={product} />; | ||
return <ProductMain selectedVariant={selectedVariant} />; | ||
} |
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
Oops, something went wrong.