From 7c834675f2fe6826995a81d135a071b266651acf Mon Sep 17 00:00:00 2001 From: "Brian.Jiang2021" Date: Thu, 25 Jan 2024 15:50:56 +0800 Subject: [PATCH] fix: prevent loop error reporting --- .../components/ChooseOptionsDialog.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/apps/storefront/src/pages/shoppingListDetails/components/ChooseOptionsDialog.tsx b/apps/storefront/src/pages/shoppingListDetails/components/ChooseOptionsDialog.tsx index da0c74ff..1cb12720 100644 --- a/apps/storefront/src/pages/shoppingListDetails/components/ChooseOptionsDialog.tsx +++ b/apps/storefront/src/pages/shoppingListDetails/components/ChooseOptionsDialog.tsx @@ -4,12 +4,14 @@ import { KeyboardEvent, SetStateAction, useEffect, + useRef, useState, } from 'react' import { FieldValues, useForm } from 'react-hook-form' import { useB3Lang } from '@b3/lang' import styled from '@emotion/styled' import { Box, Divider, TextField, Typography } from '@mui/material' +import isEqual from 'lodash-es/isEqual' import { B3CustomForm, B3Dialog, B3Sping } from '@/components' import { PRODUCT_DEFAULT_IMAGE } from '@/constants' @@ -295,6 +297,7 @@ export default function ChooseOptionsDialog(props: ChooseOptionsDialogProps) { }) const formValues = watch() + const cache = useRef(formValues) const getProductVariantId = async ( value: CustomFieldItems, @@ -374,6 +377,12 @@ export default function ChooseOptionsDialog(props: ChooseOptionsDialogProps) { } useEffect(() => { + if (cache?.current && isEqual(cache?.current, formValues)) { + return + } + + cache.current = formValues + if ( Object.keys(formValues).length && formFields.length &&