#42 Creating Cart State for Codeswear.com | NextJs Tutorial for Beginners #HarryBhai #codewithharry
_app.js import { useEffect , useState } from 'react' import Footer from '../components/Footer' import Navbar from '../components/Navbar' import '../styles/globals.css' function MyApp ({ Component , pageProps }) { const [ cart , setCart ] = useState ({}) const [ subTotal , setSubTotal ] = useState ( 0 ) useEffect (() => { console . log ( "Hey I am a useEffect form _app.js" ) try { if ( localStorage . getItem ( "cart" )){ setCart ( JSON . parse ( localStorage . getItem ( "cart" ))) } } catch ( error ) { console . error ( error ); localStorage . clear () } }, []) const saveCart = ( myCart ) => { localStorage . setItem ( "cart" , JSON . stringify ( myCart )) let subt = 0 ...