State Management
Master state handling patterns, lifecycle events, and data persistence in Eiseniiaiia applications.
๐ About State Management
State Fundamentals
Eiseniiaia provides powerful state management through the StateManager
API, enabling developers to handle component and application state with flexibility and performance. State persistence, subscription, and lifecycle management are built into the core.
๐ง State API
set(key, value)
Updates a state variable with the provided key-value pair.
// Example usage
State.set('user.preferences', {
darkMode: true,
fontSize: 16
});
get(key)
Retrieves the value associated with the specified key.
// Example usage
const preferences = State.get('user.preferences');
๐จ Practical Examples
State Persistence Example
Here's how to persist state between sessions using the storage adapter:
// Initialize persistent state
const userState = State.create({
user: {
id: 1234,
preferences: {
darkMode: true,
theme: 'ocean'
}
},
lastLogin: '2025-10-07T12:34:56Z'
});
// Access later session
const savedState = State.get('userState');
๐ Best Practices
Effective state management in Eiseniiaiia follows these principles.
-
Use
State.freeze()
for immutable operations - Organize state by feature modules
-
Subscribe to changes using
State.onChange()
๐ Cross-System State
React Integration
Seamless use with React components:
import { useState } from '@eiseniiaia/core';
// Create state slice
const userPreferences = useState('settings.user', {
mode: 'dark',
theme: 'neon'
});
Server Side
Persist session state across requests:
// Server setup
const sessionState = State.createSession('user-session', {
token: 'a1b2c3xyz',
expires: Date.now() + 3600000
});
๐ Ready to Master State?
With these tools, you're equipped to handle complex state logic in any Eiseniiaiia application. Experiment and expand your knowledge!