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!