Overview
Contract Kit provides optional React integrations that work seamlessly with your contracts. These integrations are completely optional - you can use Contract Kit without React or choose which React packages fit your needs.Available Integrations
React Query
TanStack Query integration for data fetching and caching
React Hook Form
Form handling with automatic validation
Why React Integration?
While you can use the Contract Kit client directly in React, the integration packages provide:- Contract-aware Query Helpers - Generate typed query/mutation options from contracts
- Caching & Revalidation - Built-in data management with React Query
- Form Validation - Automatic form validation with React Hook Form
- Optimistic Updates - Easy optimistic UI updates
- Loading States - Automatic loading and error state management
Quick Comparison
Without React Integration
With React Query Integration
Installation
React Query
React Hook Form
Base React Utilities
Setup
React Query Setup
Create a React Query Adapter
Features Overview
React Query Integration
- ✅ Options-first query/mutation helpers
- ✅ Intelligent caching and revalidation
- ✅ Optimistic updates
- ✅ Parallel and dependent queries
- ✅ Infinite queries
- ✅ Query invalidation
- ✅ DevTools integration
React Hook Form Integration
- ✅ Automatic form validation
- ✅ Type-safe form fields
- ✅ Error handling
- ✅ Form state management
- ✅ Submission handling
- ✅ Field-level validation
Usage Examples
Data Fetching
Mutations
Forms with Validation
Best Practices
Create resource-specific helpers
Create resource-specific helpers
Group query helpers by resource (todos, users, posts) for better organization.
Configure query defaults globally
Configure query defaults globally
Set sensible defaults in your QueryClient for staleTime, retry, etc.
Handle loading and error states
Handle loading and error states
Always provide UI feedback for loading and error states.
Invalidate queries after mutations
Invalidate queries after mutations
Ensure your UI stays in sync by invalidating related queries after mutations.
Use optimistic updates for better UX
Use optimistic updates for better UX
Implement optimistic updates for instant feedback on user actions.