Components Reference
ethers-query provides React components for easy integration with Ethereum applications.
EthersQueryProvider
The main provider component that must wrap your application:
import { EthersQueryProvider } from 'ethers-query';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
const queryClient = new QueryClient();
function App() {
return (
<QueryClientProvider client={queryClient}>
<EthersQueryProvider>
{/* Your app content */}
</EthersQueryProvider>
</QueryClientProvider>
);
}
Props
interface EthersQueryProviderProps {
/** Optional custom configuration for the provider */
config?: {
/** Custom connectors for wallet integration */
connectors?: Connector[];
/** Auto-connect behavior configuration */
autoConnect?: boolean;
/** Cache time for queries (in milliseconds) */
cacheTime?: number;
};
/** Child components */
children: React.ReactNode;
}
Configuration
Custom Connectors
You can provide custom wallet connectors:
import { InjectedConnector } from 'ethers-query';
function App() {
return (
<EthersQueryProvider
config={{
connectors: [
new InjectedConnector({
name: 'MetaMask',
shimDisconnect: true,
}),
],
}}
>
{/* Your app content */}
</EthersQueryProvider>
);
}
Auto-Connect
Enable automatic wallet connection on page load:
<EthersQueryProvider
config={{
autoConnect: true,
}}
>
{/* Your app content */}
</EthersQueryProvider>
Best Practices
- Place the provider at the root of your application
- Configure appropriate cache times for your use case
- Consider implementing error boundaries
- Use TypeScript for better type safety
- Handle provider errors gracefully