Skip to content

Commit

Permalink
Refactor useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Jul 4, 2024
1 parent 9876b5b commit bf67949
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/components/modals/LinkEvmAddressModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit bf67949

Please sign in to comment.