Manage State Like Hook on NextJs 13 with Zustand

React State Management

Nemesis Blog
4 min readAug 28, 2023
Zustand

Zustand is State Management to help manage state like get or change value that you can access through entire component without prop drilling.

We can try to build add to cart function, when Add To Cart clicked increase item on number on <CartButton/> component.

Product Page with Zustand

Step 1: Install Dependency

  1. Zustand
npm install zustand

2. Heroicon React

npm install @heroicons/react

Step 2: Build UI

  1. Modify /app/layout.tsx
import Navbar from "@/components/Navbar"
import './globals.css'
import { Montserrat } from 'next/font/google'

const font = Montserrat({
weight: "500",
preload: false
})

export const metadata = {
title: 'LearnThink',
description: 'Generated by create next app',
}

export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body className={`antialiased bg-slate-950 text-white ${font.className}`}>
<Navbar/>…

--

--