From d07e0df67aff537ba21ead953a4856c851d98455 Mon Sep 17 00:00:00 2001 From: Vladyslav Yatsenko <52505649+yivlad@users.noreply.github.com> Date: Fri, 24 Jun 2022 14:40:22 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=82=20ReadonlyNetworksProvider=20fix?= =?UTF-8?q?=20refreshing=20cycle=20(#843)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/tiny-jars-tan.md | 5 +++++ .../network/readonlyNetworks/provider.tsx | 19 +++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 .changeset/tiny-jars-tan.md 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} }