Documentation Index
Fetch the complete documentation index at: https://mintlify.com/IsaacBenavides/CicloVital/llms.txt
Use this file to discover all available pages before exploring further.
Overview
TheChatContext provides centralized state management for the currently active chat conversation in the CicloVital application. It automatically persists the selected chat to localStorage for continuity across sessions.
Context Shape
Properties
The currently selected chat conversation object, or
null if no chat is selected.Function to update the current chat. Pass
null to deselect.Provider Component
ChatProvider
Wraps your application to provide chat context to all child components.Features
- Automatic Persistence: Current chat is automatically saved to localStorage
- Session Recovery: Loads the last selected chat from localStorage on initialization
- Safe Storage: Includes error handling for localStorage operations
- Deselection Support: Removes data from localStorage when chat is set to
null
Usage
Consuming the Context
Selecting a Chat
Clearing the Selected Chat
Checking if a Chat is Active
Implementation Details
Source Files
src/contexts/ChatContext.js- Context definitionsrc/contexts/ChatProvider.jsx- Provider implementation
localStorage Key
The context stores chat data under the key"chat" in localStorage.
Initial State
On mount, the provider attempts to load the current chat from localStorage. If no data exists or parsing fails, it defaults tonull.
Best Practices
The entire chat object is persisted to localStorage. For large chat histories, consider storing only the chat ID and fetching full details from a server.
Common Patterns
Auto-selecting First Chat
Related
- UserContext - Manages user authentication
- ThemeContext - Manages theme preferences
