Overview
TheDriftProvider is the central component for integrating Drift Protocol into your React application. It:
- Wraps
DriftWalletProviderfor wallet management - Initializes and manages the Drift client connection
- Provides hooks for accessing Drift data
- Handles polling and subscription logic
- Manages screen size and responsive breakpoints
Basic Setup
Configuration Options
DriftProviderProps
/home/daytona/workspace/source/react/src/providers/DriftProvider.tsx:39-43
Advanced Configuration
Custom Drift Client Config
Pass additional configuration to the Drift SDK client:Disabling Features
Optimize your app by disabling unused features:Geoblocking Configuration
Handle geoblocking with a custom callback:Breakpoints Configuration
Breakpoints are required and used for responsive design:Provider Hooks
TheDriftProvider automatically initializes several hooks:
Connection Initialization
Initializes the Drift client and connection (enabled by default):/home/daytona/workspace/source/react/src/providers/DriftProvider.tsx:57-60
Idle Polling Rate Switcher
Automatically reduces polling rate when user is idle:SOL Balance Subscription
Automatically subscribes to the connected wallet’s SOL balance:/home/daytona/workspace/source/react/src/providers/DriftProvider.tsx:61
Screen Size Tracking
Tracks current screen size based on breakpoints:/home/daytona/workspace/source/react/src/providers/DriftProvider.tsx:62
Accessing the Drift Store
The provider initializes the global Drift store:Developer Tools
In development, the Drift store is exposed on the window object:/home/daytona/workspace/source/react/src/providers/DriftProvider.tsx:48-51
Provider Architecture
TheDriftProvider has a two-layer architecture:
- DriftWalletProvider (outer): Manages wallet adapters and connections
- DriftProviderInner (inner): Initializes Drift-specific hooks and functionality
/home/daytona/workspace/source/react/src/providers/DriftProvider.tsx:69-91
Complete Example
Best Practices
- Always provide breakpoints: This is required and ensures responsive design works correctly
- Disable unused features: Improve performance by disabling features you don’t need
- Use a single DriftProvider: Only wrap your app root, don’t nest multiple providers
- Access store efficiently: Use Zustand selectors to prevent unnecessary re-renders
Next Steps
Using Hooks
Learn about available hooks for accessing Drift data
Custom Components
Build custom components with Drift functionality