DEV Community

Cover image for NextJS simple shopping cart

NextJS simple shopping cart

Ha Tuan Em on March 14, 2021

After a week of learning and working with Next.JS. I had to build a simple application using the topic is a shopping cart in e-commerce. A lot of d...
Collapse
 
justicebringer profile image
Gabriel •

It was good if you showed the all code of the index.js file.
For other guys who were stuck on the creation of the store, follow the Usage guide: github.com/kirill-konshin/next-red...

Long story short, in your _app.tsx file:

import React, {FC} from 'react';
import {AppProps} from 'next/app';
import {wrapper} from '../components/store';

const WrappedApp: FC<AppProps> = ({Component, pageProps}) => (
    <Component {...pageProps} />
);

export default wrapper.withRedux(WrappedApp);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
hte305 profile image
Ha Tuan Em • • Edited

Absolutely, I had edited this article with link repository below the article.
Thanks you for reading.
And I got have a new post deploy express to Vercel. Hope you will read this article.

Collapse
 
michelc profile image
Michel •

But this is not an Express application? Are you planning a post to explain how you deployed your shopping cart to Vercel?

Thread Thread
 
hte305 profile image
Ha Tuan Em •

Yep, if you want, I will do that for you. Follow me, it's comming in this week.

Collapse
 
justicebringer profile image
Gabriel •

An upgraded setCookie function

export function setCookie(
  key: string,
  value: string | object,
  days: number = 30,
  sameSite: 'Lax' | 'strict' | 'Strict' | 'lax' | 'none' | 'None' | undefined = 'Lax'
) {
  let expires: number | Date | undefined;
  if (days) {
    let date = new Date();
    date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
    expires = date;
  }

  jsCookie.set(key, JSON.stringify(value), { expires: expires, sameSite: sameSite });
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
hte305 profile image
Ha Tuan Em •

Thanks you for code.

Collapse
 
uguremirmustafa profile image
uguremirmustafa •

Thank you, setCookie and getCookie was halpful for me!

Collapse
 
hte305 profile image
Ha Tuan Em •

You are welcome 😀😉

Collapse
 
kleguizamon profile image
Kevin Leguizamon •

Great👌🏽

Collapse
 
hte305 profile image
Ha Tuan Em •

Thanks 😃

Collapse
 
orionitcenter profile image
Orion IT Center •

Hi Good day
How to display the cart page?
thank you.

Collapse
 
hte305 profile image
Ha Tuan Em •

Everything has saved in cookie. You can use getCookie function to fetch data and processing with your logic.

Collapse
 
couponsvacom profile image
Couponsva •

Thanks you for code.
And I got have a new post couponsva. Hope you will read this article.