State Management
This document outlines how application state is managed within the frontend of the Chat App MERN project. We leverage the zustand library for efficient and organized state management, providing a centralized approach to handling authentication, chat-related data, and theme preferences.
Core State Stores
The application utilizes three primary zustand stores to manage different aspects of its state:
useAuthStore
This store is responsible for managing all authentication-related state, including user information, loading states for authentication operations, and real-time socket connections.
authUser: Stores the currently logged-in user's data. If no user is logged in, it'snull.isSigningUp,isLoggingIn,isUpdatingProfile: Boolean flags to indicate the status of respective authentication operations, useful for displaying loading indicators.isCheckingAuth: A flag to manage the initial authentication check when the application loads.onlineUsers: An array storing the IDs of currently online users.- : Holds the active socket.IO client instance for real-time communication.