-
Notifications
You must be signed in to change notification settings - Fork 0
State Management
PhobiaCide edited this page Apr 15, 2025
·
1 revision
This page outlines how application state is managed in the EVE Companion App using the Zustand library. Zustand provides a minimal, unopinionated store that is ideal for managing global state in modular apps like ours.
We chose Zustand because it:
- Has a simple, hook-based API
- Supports persistent and reactive state out of the box
- Plays well with Electron, IndexedDB, and class-based patterns
- Doesnโt require boilerplate or context providers
Zustand stores are defined in individual files in the following folder:
src/js/stores/
Each store manages a slice of state related to a specific domain, such as:
- Active character
- Selected fit
- UI layout preferences
- Drag/drop window states
import { create } from 'zustand';
const useCharacterStore = create((set) => ({
activeCharacterId: null,
setActiveCharacter: (id) => set({ activeCharacterId: id })
}));
export default useCharacterStore;Use inside a React component:
const characterId = useCharacterStore((s) => s.activeCharacterId);Zustand state lives in the renderer process and does not persist across restarts unless paired with:
-
electron-storeโ persistent config values -
dexie.jsโ durable IndexedDB state (e.g. character cache)
Zustand updates state reactively. Components or logic that subscribe to state changes will re-render when state is updated.
This works great for:
- Toggling UI elements (windows, tabs)
- Switching context (character, corp, region)
- Live data visualization and updates
| Pattern | Use Case |
|---|---|
| Zustand only | Volatile, UI-scoped state |
| Zustand + Dexie | Cached live data from ESI (e.g., fits, types) |
| Zustand + electron-store | Settings, preferences, login tokens |
- Log state directly:
console.log(useStore.getState()) - Add devtools middleware if needed:
import { devtools } from 'zustand/middleware' - Use selectors to avoid re-renders:
useStore(state => state.key)
- Zustand is our main state manager for renderer processes
- Easy to integrate with persistent storage layers
- Encourages composable and reactive UI behavior