Overview
The React package provides a comprehensive set of hooks for accessing Drift Protocol data and functionality. All hooks are built on Zustand and provide efficient, selector-based state management.Core Hooks
useCommonDriftActions
Returns all available Drift actions for interacting with the protocol:/home/daytona/workspace/source/react/src/hooks/useCommonDriftActions.tsx:1-12
useWalletContext
Access the current wallet connection state:/home/daytona/workspace/source/react/src/hooks/useWalletContext.tsx:5-11
useDriftClientIsReady
Check if the Drift client is initialized and subscribed:/home/daytona/workspace/source/react/src/hooks/useDriftClientIsReady.tsx:1-13
useSolBalance
Access the connected wallet’s SOL balance:/home/daytona/workspace/source/react/src/hooks/useSolBalance.tsx:10-79
Account Hooks
useAccountExists
Check if the connected wallet has a Drift account:/home/daytona/workspace/source/react/src/hooks/useAccountExists.tsx:10-44
useAccountCreationCost
Get the cost to create a new Drift account:RPC & Connection Hooks
useCurrentRpc
Access and update the current RPC endpoint:/home/daytona/workspace/source/react/src/hooks/useCurrentRpc.tsx:12-40
useRpcLatencies
Monitor RPC endpoint latencies:useHandleBadRpc
Automatically detect and switch away from bad RPC endpoints:Priority Fee Hooks
usePriorityFeeUserSettings
Manage user’s priority fee preferences:usePriorityFeeSubscriber
Subscribe to real-time priority fee updates:usePriorityFeesPollingRate
Get the current priority fee polling rate:Utility Hooks
useImmediateInterval
Run a function immediately and then at intervals:useSyncLocalStorage
Synchronize state with localStorage:useDisableScroll
Disable page scrolling (useful for modals):useTargetedPopover
Manage popover state and positioning:Feature Hooks
useEmulation
Check if emulation mode is enabled:useGeoBlocking
Check if user is geo-blocked:useDevSwitchIsOn
Check if developer mode is enabled:useIsMainnet
Check if connected to mainnet:useLastAcknowledgedTerms
Track when user last acknowledged terms:Chart Hooks
useGroupHistoricalPricesByAverage
Group historical price data by time interval:Store Access Pattern
For maximum flexibility, access the store directly:Best Practices
- Use Selectors: Always use Zustand selectors to prevent unnecessary re-renders
- Check Ready State: Always check if Drift client is ready before using it
- Handle Loading States: Most hooks may return undefined initially
- Singleton Hooks: Some hooks use
react-singleton-hookto ensure single instance
Next Steps
Custom Components
Learn how to build custom components using these hooks