For simplified state management with pre-built hooks, see the React Hooks Approach.
Prerequisites
You must have a Para account set up with authentication methods enabled in your Developer Portal. Install the Web SDK:Para Client Setup
First, create a Para client instance that you’ll use throughout your application:Direct Client Methods
Custom Hook Implementation Examples
Here are examples of how to create custom hooks using the Para client directly with React Query:Authentication Hook
Account State Hook
Wallet Management Hook
Message Signing Hook
Advanced Custom Hook Examples
OAuth Authentication Hook
Session Management Hook
Error Handling Hook
Benefits of Direct Client Approach
- Full Control: Complete control over state management and caching strategies
- Custom Return Interfaces: Design return interfaces that match your application’s needs
- Enhanced Error Handling: Add custom error processing and retry logic
- Flexible Polling: Implement custom polling behavior for long-running operations
- Performance Optimization: Optimize queries and mutations for your specific use case
Trade-offs
- More Boilerplate: Requires more code to implement the same functionality
- Manual Cache Management: You need to handle cache invalidation manually
- Type Safety: May need to define custom TypeScript interfaces
- Maintenance: More code to maintain and update as the SDK evolves
Best Practices
- Centralized Client: Create a single Para client instance and share it across your app
- Query Key Consistency: Use consistent query key patterns for cache management
- Error Boundaries: Implement error boundaries to catch and handle errors gracefully
- Loading States: Provide clear loading states for better user experience
- Cache Invalidation: Invalidate relevant queries after mutations
- Type Safety: Define proper TypeScript interfaces for your custom hooks