UNPKG

subgraph-sync

Version:

React hooks and components for tracking subgraph synchronization states with Apollo Client

41 lines (40 loc) 1.34 kB
import React from "react"; import { SubgraphSyncContextType, SyncConfig } from "../types"; interface SubgraphSyncProviderProps { /** Child components */ children: React.ReactNode; /** Default configuration applied to all transactions */ defaultConfig?: SyncConfig; } /** * Context provider for managing multiple subgraph sync states. * Useful for tracking multiple transactions or queries simultaneously. * * Note: Due to React's Rules of Hooks, sync states must be managed manually. * Components should call useSubgraphSync themselves and update the context * using updateSyncState. * * @example * ```tsx * function App() { * return ( * <SubgraphSyncProvider defaultConfig={{ pollInterval: 3000 }}> * <YourComponents /> * </SubgraphSyncProvider> * ); * } * * function YourComponent() { * const { registerTransaction, updateSyncState } = useSubgraphSyncContext(); * const txId = registerTransaction({ blockNumber: 1000000 }); * const syncState = useSubgraphSync({ blockNumber: 1000000 }); * * useEffect(() => { * updateSyncState(txId, syncState); * }, [syncState, txId, updateSyncState]); * } * ``` */ export declare const SubgraphSyncProvider: React.FC<SubgraphSyncProviderProps>; export declare const useSubgraphSyncContext: () => SubgraphSyncContextType; export {};