CartProvider and prop onCreate #1880
-
Hey, Error in terminal: App.server.jsx
Unfortunately my React skills aren't good. Any suggestion how to use callback/props will be good. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @MichaelRise, Thanks for posting. Please read this to understand the limitations of In short, because 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
import { CartProvider } from '@shopify/hydrogen';
// wrapper for CartProvider
export function CartProviderUI({countryCode, children}) {
return (
<CartProvider countryCode={countryCode} onCreate={() => console.log('cart created')}>
{children}
</CartProvider>
} Then instead of importing Hope this helps. |
Beta Was this translation helpful? Give feedback.
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 asprops
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 />
compomentCartProviderUI.client.jsx