Overview
Crocante uses React Context API for managing global application state. Context providers wrap the application and provide access to shared state and functionality through custom hooks.Provider Architecture
All providers are composed in theProvidersWrapper component:
SessionProvider
Manages user authentication state and session lifecycle.Context Type
Usage
Features
- Auto-polling: Refreshes user data at intervals (configured via
POLL_USER_DATA_INTERVAL) - Session Expiry: Integrates with
SessionExpiryManager - Auth Events: Listens for
auth-expiredevents - Query Integration: Uses React Query for data fetching
- Logout Cleanup: Clears cache and local storage
Implementation Details
ToastProvider
Manages global toast notifications.Context Type
Usage
Features
- Auto-dismiss: Toasts automatically hide after 5 seconds
- Multiple Types: Success, error, warning, info variants
- Manual Control: Can manually hide toasts
- Global Access: Available throughout the app
Implementation Details
CustomHeaderProvider
Manages dynamic header content for pages.Context Type
Usage
Features
- Page-specific Headers: Each page can customize header
- React Node Support: Any React component can be header
- Automatic Cleanup: Clear header on unmount
- Dynamic Updates: Header updates reactively
Implementation Details
SessionExpiryManager
Internal component that handles session expiration warnings.Location
context/session-expiry-manager.tsx
Functionality
Automatically integrated intoSessionProvider. Monitors session expiration and displays warning modal using the useSessionExpiry hook.
AuthExpiredListener
Listens for authentication expiration events.Location
context/auth-expired-listener.tsx
Functionality
Listens for the globalauth-expired event and triggers the authentication modal to re-authenticate the user.
Error Handling
All context hooks throw errors when used outside their provider:Provider Composition Pattern
The platform uses a single wrapper component to compose all providers:- Centralizes provider setup
- Ensures correct provider order
- Simplifies testing
- Makes provider dependencies explicit
Next Steps
Session Management
Learn about authentication
Custom Hooks
Explore React hooks
