React Stores
Drift Common provides several Zustand-based stores for managing global application state. These stores handle wallet connections, Drift client state, oracle prices, and UI state.Available Stores
useCommonDriftStore
The main store for Drift client state, wallet connections, and core application data.useOraclePriceStore
Manages oracle price data for all markets.useScreenSizeStore
Tracks responsive breakpoints and screen size.useCommonDriftStore
The central store for managing Drift client connections, user accounts, and wallet state.Import
Initialization
Before using the store, you must initialize it with your environment configuration:Store Shape
Usage Examples
Accessing Wallet State
Checking Drift Client Status
Accessing User Accounts
Updating Store State
useOraclePriceStore
Manages oracle price data for all markets in the application.Import
Store Shape
Usage Examples
Getting Market Price
Accessing All Market Prices
useScreenSizeStore
Tracks the current screen size based on configurable breakpoints.Import
Store Shape
Default Breakpoints
Breakpoints follow Tailwind CSS conventions:Usage Examples
Setting Up Screen Size Sync
Using Custom Breakpoints
Responsive Components
Mobile Detection Helper
Priority Fee Stores
Drift Common also includes stores for managing priority fees. These are typically used internally by the Drift providers but can be accessed if needed. See the Priority Fees Hook documentation for more details on working with priority fees.Best Practices
Store Initialization
Always initialize stores before rendering your app:Selective Subscriptions
Only subscribe to the state you need to avoid unnecessary re-renders:Clearing User Data
Clear user data when disconnecting:Related
- DriftProvider - Provider components that manage these stores
- Drift Client Hook - Hook for accessing the Drift client
- Oracle Price Hook - Hook for oracle price data