diff --git a/.changeset/tiny-jars-tan.md b/.changeset/tiny-jars-tan.md new file mode 100644 index 000000000..e6a5f506d --- /dev/null +++ b/.changeset/tiny-jars-tan.md @@ -0,0 +1,5 @@ +--- +'@usedapp/core': patch +--- + +Fix refreshing cycle in ReadonlyNetworksProvider diff --git a/packages/core/src/providers/network/readonlyNetworks/provider.tsx b/packages/core/src/providers/network/readonlyNetworks/provider.tsx index c4ad90306..2a61df03f 100644 --- a/packages/core/src/providers/network/readonlyNetworks/provider.tsx +++ b/packages/core/src/providers/network/readonlyNetworks/provider.tsx @@ -1,4 +1,4 @@ -import { ReactNode, useCallback, useEffect, useReducer, useState } from 'react' +import { ReactNode, useCallback, useEffect, useMemo, useReducer, useState } from 'react' import { providers } from 'ethers' import { useConfig } from '../../../hooks' import { Providers } from './model' @@ -70,14 +70,13 @@ export function ReadonlyNetworksProvider({ providerOverrides = {}, children }: N } }, [providers, getPollingInterval]) - return ( - - {children} - + const networks = useMemo( + () => ({ + providers, + updateNetworkState: dispatchNetworkState, + }), + [providers, dispatchNetworkState] ) + + return {children} }