Skip to content

Context

Principle

Context is for cross-page app state. Server datasets belong to query hooks (TanStack), not context.

Current Contexts

  • auth - session identity, current user, auth actions
  • system - system permission catalog (from /system/permissions)
  • notifications - global notifications + unread count
  • ui - global busy/session UI state
  • theme - theme and persistence behavior

Aggregation

src/context/index.ts contains:

  • static registry (getContext, getContexts)
  • wrapper helper (wrapWithContexts)
  • app wrapper (AppContextProvider)

This allows one import point and consistent provider order.

Context Usage Guide

Naming

Provider function names use ...ContextProvider for clarity:

  • AuthContextProvider
  • SystemContextProvider
  • NotificationsContextProvider
  • UiContextProvider
  • ThemeContextProvider

Import Pattern

Prefer importing from @/context for hooks/providers:

  • useAuth, usePermissions, useSystem, useNotifications, useUi, useTheme

Do / Don't

  • Do put app-level state in context.
  • Do not put large lists/details/tables in context.
  • Do not duplicate the same server data in context and query cache.