Next.js › State Management in Next.js Apps
What is local component state, and when is it enough for managing data in a Next.js application?
BeginnerAnswer
Local component state, managed with the useState hook inside a client component, is enough when a piece of data only matters to that one component and its direct children, such as whether a dropdown menu is currently open, without needing to be shared more broadly across the rest of the application.
'use client';
import { useState } from 'react';
export default function Dropdown() {
const [isOpen, setIsOpen] = useState(false);
return <button onClick={() => setIsOpen(!isOpen)}>{isOpen ? 'Close' : 'Open'}</button>;
}Real-world example A navigation menu tracks whether it is currently expanded using simple local state, since no other part of the application ever needs to know or care about that specific detail.