Skip to content

CartProvider and prop onCreate #1880

Answered by juanpprieto
MichaelRise asked this question in Help
Discussion options

You must be logged in to vote

Hi @MichaelRise,

Thanks for posting. Please read this to understand the limitations of .server components.

In short, because App.server.jsx is a server component it can't have inlined functions as props in any of it's direct children. .server components are only executed in the server.

To use CartProvider callbacks, you will need to wrap it inside a client component and use the callbacks you want inside there. e.g — Create a <CartProviderUI /> compoment

CartProviderUI.client.jsx

import { CartProvider } from '@shopify/hydrogen';

// wrapper for CartProvider
export function CartProviderUI({countryCode, children}) {
 return (
   <CartProvider countryCode={countryCode} onCreate={() => console.l…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@MichaelRise
Comment options

@this-alias
Comment options

Answer selected by MichaelRise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants