local-vs-global-state

Determine local versus global state strategies for React 19 components.

Updated Nov 21, 2025
One-click install
npx skills add https://github.com/djankies/claude-configs --skill local-vs-global-state
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: local-vs-global-state
Source: https://github.com/djankies/claude-configs/tree/main/react-19/concerns/state/skills/local-vs-global-state
Command: npx skills add https://github.com/djankies/claude-configs --skill local-vs-global-state

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Deciding whether to use local state (useState), lifted state, or global state (Context) is crucial for application performance, maintainability, and avoiding prop drilling. This Skill guides you to the optimal strategy.

Core Features & Use Cases

  • Local State (useState): Best for state needed only within a single component or its direct children, or for frequently changing UI-specific state.
  • Lifted State: Ideal when two sibling components need to share state, managed by their common parent.
  • Context API (use()): Use for global configuration (theme, auth), or when many components at different nesting levels need the same state, avoiding deep prop drilling.
  • Anti-Patterns: Identifies and helps avoid common mistakes like using Context for frequently changing state, which can cause unnecessary re-renders.
  • Use Case: Analyze the ThemeSwitcher component and its usage across the application to determine if theme state should be local, lifted, or managed via Context, optimizing for performance and ease of access.

Quick Start

Analyze the src/components/UserProfile.js component and determine if the user's profile data should be managed with local state or Context.

Frequently Asked Questions about local-vs-global-state

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
When should I use local state with useState vs global state in React?

Use local state (useState) for UI-specific state needed only within a single component or its direct children. Use global state (Context) for configuration like theme, auth, or locale that many deeply nested components need, avoiding prop drilling. Lift state to a parent when sibling components share concerns.

How do I avoid prop drilling in React 19 components?

Avoid prop drilling by lifting shared state to a common parent component, or use Context API with the use() hook to make state accessible across your component tree without passing props through intermediate components.

What's the difference between lifted state and Context API in React?

Lifted state passes data through a parent to sibling components and works best for nearby components. Context API distributes state across distant or deeply nested components without passing props through every level, ideal for global configuration.

Why shouldn't I use Context for frequently changing state?

Context triggers re-renders of all consuming components when state updates, even if they only use part of it. Frequently changing state causes excessive re-renders and performance degradation; use useState locally or a specialized state management library instead.

How do I decide between useState, lifted state, and Context for React 19?

Apply a decision flow: use useState for single-component or direct-child state; lift state when siblings share concerns; use Context for global configuration, theme, auth, or cross-cutting state across deep trees. Avoid Context for rapidly changing state.

Can I use Context with React 19's use() hook for state management?

Yes. React 19's use() hook enables Context consumption in components. Use Context with use() for infrequent updates to global configuration; avoid it for frequently changing state to minimize unnecessary component re-renders.