From b2a467412ab59f4a290b6e1ab60980fbfe74e7f7 Mon Sep 17 00:00:00 2001 From: Noah Zinsmeister Date: Thu, 28 Apr 2022 15:25:37 -0400 Subject: [PATCH] pass hooks through context --- packages/core/src/provider.tsx | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/core/src/provider.tsx b/packages/core/src/provider.tsx index 73ccb19..24f248b 100644 --- a/packages/core/src/provider.tsx +++ b/packages/core/src/provider.tsx @@ -22,6 +22,7 @@ export type Web3ContextType = { provider: T | undefined ENSNames: ReturnType ENSName: ReturnType + hooks: ReturnType } const Web3Context = createContext(undefined) @@ -50,6 +51,7 @@ export function Web3ReactProvider({ network, lookupENS = true, }: Web3ReactProviderProps) { + const hooks = getPriorityConnector(...connectors) const { usePriorityConnector, useSelectedChainId, @@ -61,7 +63,7 @@ export function Web3ReactProvider({ useSelectedProvider, useSelectedENSNames, useSelectedENSName, - } = getPriorityConnector(...connectors) + } = hooks const priorityConnector = usePriorityConnector() const connector = connectorOverride ?? priorityConnector @@ -94,6 +96,7 @@ export function Web3ReactProvider({ provider, ENSNames, ENSName, + hooks, }} > {children} @@ -101,8 +104,8 @@ export function Web3ReactProvider({ ) } -export function useWeb3React() { - const web3 = useContext(Web3Context as Context | undefined>) - if (!web3) throw Error('useWeb3React can only be used within the Web3ReactProvider component') - return web3 +export function useWeb3React(): Web3ContextType { + const context = useContext(Web3Context as Context | undefined>) + if (!context) throw Error('useWeb3React can only be used within the Web3ReactProvider component') + return context }