Store Patterns
Type-safe state management patterns without action dispatching overhead.
Prerequisites
For complete setup instructions including store definitions, context creation, and provider configuration, see Basic Store Setup.
All store pattern examples reference the shared setup guide for:
- Store type definitions and configurations
- Context creation patterns and naming conventions
- Provider composition and organization
- Export patterns and integration strategies
Overview
Store patterns provide excellent type inference and simplified API for pure state management scenarios.
Available Store Patterns
Core Patterns
- Basic Usage - Fundamental Store Only pattern with type inference
- useStoreValue Patterns - Core
useStoreValuesubscription patterns - useStoreSelector Patterns - Multiple store selection with
useStoreSelector - useStoreManager API - Low-level store access with
useStoreManagerhook
Computed Value Patterns
- Basic Computed Patterns - Getting started with computed values
- useComputedStore Overview - Comprehensive computed pattern guide
- useComputedStore Patterns - Complete reference (all patterns)
Performance & Optimization
- Store Performance Overview - Performance optimization guide
- Immutability & Comparison Integration - Key integration guide
- Memoization Patterns - Prevent unnecessary re-renders
- Batching Patterns - Batch multiple updates
- Subscription Optimization - Optimize subscriptions
- Comparison Strategies - Choose the right comparison method
- Lazy Evaluation Patterns - Defer expensive operations
- Memory Management - Prevent memory leaks
- Debugging & Development - Development tools and debugging
- Error Handling & Recovery - Robust error handling
Advanced Patterns
- withProvider Pattern - Higher-Order Component pattern for automatic Provider wrapping
- Store Configuration - Store configuration and comparison strategies
Quick Reference
| Pattern Category | Purpose | Best For |
|---|---|---|
| Core Patterns | Basic store operations | Data layers, subscriptions, multi-store access |
| Computed Values | Derived state calculations | Reactive calculations, data transformations |
| Performance & Optimization | Performance optimization | Memory management, batching, memoization |
| Advanced Patterns | Complex scenarios | Provider composition, custom configurations |
Detailed Pattern Reference
| Specific Pattern | Purpose | Use When |
|---|---|---|
| Basic Usage | Type-safe state management | Starting with stores |
| useStoreValue | Core store subscriptions | Selective updates, conditional subscriptions |
| useComputedStore | Derived state calculations | Computed values, multi-store calculations |
| Memoization | Prevent re-renders | Performance optimization needed |
| Memory Management | Resource efficiency | Memory leaks detected |
| Error Handling | Robust operations | Production applications |
When to Use Store Patterns
- Pure State Management: No complex business logic needed
- Data Layers: Managing application data without side effects
- Configuration State: User preferences, app settings
- UI State: View state, form state, component state
- Reactive Data: Data that needs reactive subscriptions
Key Features
- ✅ Excellent type inference without manual type annotations
- ✅ Simplified API focused on store management
- ✅ Direct value or configuration object support
- ✅ No need for separate
createStorecalls - ✅ Multiple comparison strategies for performance
- ✅ HOC pattern for automatic Provider wrapping
Integration
Store patterns work best when combined with:
- Action Patterns for business logic
- Ref Patterns for DOM manipulation
- Async Patterns for safe async operations
Architecture & Troubleshooting
Technical Architecture
- Immutability Architecture - Deep technical dive into Immer and comparison system integration
Common Issues
- Immer & Comparison Misconceptions - Common misconceptions and solutions
Key Learning Path
- Start with: Basic Usage and useStoreValue Patterns
- Understand integration: Immutability & Comparison Integration
- Optimize performance: Store Performance Overview
- Troubleshoot issues: Common Misconceptions