From 1894f3cae9612b9e05c4459274c4e0f19eb88594 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Tue, 12 Jul 2022 13:01:08 +0200 Subject: [PATCH] Check if the current state address equals input value before updating address state (#203) * Check if the current state address equals input value before updating address state * disable minimizing * exclude updateAddressState from deps * Revert "exclude updateAddressState from deps" This reverts commit 5965f27d929a91b4f4c95df60c62d4fe35773171. --- babel.config.js | 2 +- src/inputs/AddressInput/index.tsx | 7 ++++++- webpack.config.js | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/babel.config.js b/babel.config.js index 19646cbe..7175faeb 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,6 +1,6 @@ module.exports = { presets: [ - ['@babel/preset-env', { targets: { node: 'current' } }], + ['@babel/preset-env', { targets: '> 3%, not dead' }], '@babel/preset-typescript', '@babel/preset-react', ], diff --git a/src/inputs/AddressInput/index.tsx b/src/inputs/AddressInput/index.tsx index b5c64b44..42ecd1c1 100644 --- a/src/inputs/AddressInput/index.tsx +++ b/src/inputs/AddressInput/index.tsx @@ -143,7 +143,12 @@ function AddressInput({ // when user switch the network we update the address state useEffect(() => { - updateAddressState(inputRef.current?.value); + // Because the `address` is going to change after we call `updateAddressState` + // To avoid calling `updateAddressState` twice, we check the value and the current address + const inputValue = inputRef.current?.value; + if (inputValue !== address) { + updateAddressState(inputRef.current?.value); + } }, [networkPrefix, address, updateAddressState]); // when user types we update the address state diff --git a/webpack.config.js b/webpack.config.js index 9fea02cd..77da6380 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -62,4 +62,7 @@ module.exports = { fs: 'empty', child_process: 'empty', }, + optimization: { + minimize: false, + }, };