From bf6794940bcdc69289306519607a678c9be9bede Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Thu, 4 Jul 2024 18:50:59 +0700 Subject: [PATCH] Refactor useEffect --- src/components/modals/LinkEvmAddressModal.tsx | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/components/modals/LinkEvmAddressModal.tsx b/src/components/modals/LinkEvmAddressModal.tsx index dd04f66ca..b19088ba2 100644 --- a/src/components/modals/LinkEvmAddressModal.tsx +++ b/src/components/modals/LinkEvmAddressModal.tsx @@ -23,20 +23,18 @@ export default function LinkEvmAddressModal( const { evmAddress: myEvmAddress } = useLinkedEvmAddress() useEffect(() => { - if (props.isOpen && myEvmAddress && !isAfterSubmit.current) { - setEvmAddress(myEvmAddress) - reset() - isAfterSubmit.current = false - } - }, [props.isOpen, myEvmAddress, reset]) - - useEffect(() => { - if (props.isOpen && isAfterSubmit.current) { - props.closeModal() - isAfterSubmit.current = false + if (props.isOpen && myEvmAddress) { + if (!isAfterSubmit.current) { + setEvmAddress(myEvmAddress) + reset() + isAfterSubmit.current = false + } else { + props.closeModal() + isAfterSubmit.current = false + } } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [myEvmAddress, props.isOpen]) + }, [props.isOpen, myEvmAddress, reset]) const onSubmit = (e: any) => { e.preventDefault()