Next.js cart storage
See original GitHub issueHi!
I’m using the library with Next.js.
When trying to using the library in pages which rendered server-side, the content of the server doesn’t match the client. It seems this could be related to the cart being stored using localStorage and this is not available on the server, only in the client.
One thought it to use the storage prop, have you ran into this issue before ?
I tried using the storage prop and the following snipped fails with the following error. Could you provide an example of how the prop should be used and its initial value
function MyApp({ Component, pageProps }) {
const [cart, setCart] = useState();
return (
<div>
<CartProvider storage={() => [cart, setCart]}>
<Layout>
<Component {...pageProps} />;
</Layout>
</CartProvider>
</div>
);
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Building a Next.js shopping cart app - LogRocket Blog
Learn how to build a Next.js application by building a shopping cart web app for a fictional game store with product category pages....
Read more >next.js - NextJS localStorage and Context of Shopping Cart
Your localstorage has been writen when you reload the page. Try the following way to prevent set item in localstorage when init.
Read more >NextJS simple shopping cart - DEV Community
Setup the redux to make the magic in the client side. Initial the store component in redux. // ./store/index.js import { createStore ...
Read more >What would you use to save cart items? : r/nextjs - Reddit
I'm making an ecommerce store. What would you use to store the cart items so they persist on reload and/or come back to...
Read more >Create a Shopping Cart Page to Manage Products to ...
Create an eCommerce Store with Next.js and Stripe Checkout ... Instructor: [0:00] When we try to add them to cart, we can see...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey, has there been a solution for this yet in NextJS? I’m getting a server and client mismatch on page reload.
@notrab That approach is working for us.