# apps/web/src/state
dir: apps/web/src/state

index: apps/web/src/state/.pi-map.index.md

## role
Centralized React state management package providing context-based global state for authentication, real-time events, notifications, sessions, and UI feedback across the web application.
## files
- auth.tsx | Provides React authentication context with session state management, user data, and auth operations (refresh/logout). | exp: AuthProvider, useAuth | dep: react, ../api/client, ../types
- events.tsx | Creates a React context provider for real-time instance events with connection status and reconnect tracking | exp: func:EventProvider({ children }: { children: React.ReactNode }), call:useEvents, call:useMemo, func:useEventContext(), call:useContext | dep: react, ../hooks/use-events, ../types/events
- notifications.tsx | Provides a React context that manages notification state with optimistic updates, polling, and visibility-aware fetching for a notification dropdown UI. | exp: NotificationContextValue, NotificationContext, func:NotificationProvider({ children, }: { children: React.ReactNode; }), call:useState, call:useRef, call:useCallback, call:getUnreadCount, call:setUnreadCount, call:clearInterval, call:console.error, call:setIsLoading, call:getNotifications, call:setNotifications, call:fetchUnreadCount, call:setInterval, call:fetchList, call:useEffect, call:stopPolling, call:startPolling, call:document.addEventListener, call:document.removeEventListener, call:currentNotifications.find, call:currentNotifications.map, call:new Date().toISOString, call:Math.max, call:setError, call:markNotificationRead, call:markAllNotificationsRead, call:currentNotifications.filter, call:dismissNotification, call:clearAllNotifications | dep: react, ../api/notifications, React
- sessions.tsx | Provides a React context for managing user sessions with server polling, local state updates, and CRUD operations. | exp: SessionsContextType, SessionsProvider, useSessions | dep: react, ../api/sessions
- toast.tsx | Provides a React toast notification system with context-based state management, auto-dismiss timers, and imperative API access. | exp: ToastSeverity, ToastItem, toast, func:ToastProvider({ children }: { children: React.ReactNode }), call:useState, call:useRef, call:useCallback, call:setToasts, call:prev.filter, call:timersRef.current.get, call:clearTimeout, call:timersRef.current.delete, call:Date.now, call:setTimeout, call:removeToast, call:timersRef.current.set, call:useEffect, call:addToast, func:useToast(), call:useContext, raise:Error | dep: react, React
## arch
React Context pattern with provider/consumer model, each module implementing independent singleton contexts with imperative APIs, optimistic updates, polling-based synchronization, and side-effect management via useEffect hooks.
## tags
call:use, context, toast, call:set, notification, react, provider, notifications
## symbols
- EventProvider
- useEventContext
- NotificationProvider
- ToastProvider
- useToast
- AuthProvider
- useAuth
- call:useEvents
## workflows
- change state behavior
  read: auth.tsx, events.tsx, notifications.tsx
## dirty
-
