From 09cd9e99c26e0acd6c1fd54bd927620c62a9f21b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Artur=20Magalh=C3=A3es?= Date: Mon, 11 Dec 2023 15:19:07 -0300 Subject: [PATCH] added: added a dependency on useEffect call and selectedSeller --- react/components/SellerWrapper/SellerWrapper.tsx | 2 +- react/hooks/useSelectSeller.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/react/components/SellerWrapper/SellerWrapper.tsx b/react/components/SellerWrapper/SellerWrapper.tsx index 825664b5..65d021ab 100644 --- a/react/components/SellerWrapper/SellerWrapper.tsx +++ b/react/components/SellerWrapper/SellerWrapper.tsx @@ -17,7 +17,7 @@ const SellerWrapper = ({ children }: SellerWrapperProps) => { const { selectedItem } = useProduct() ?? {} useEffect(() => { - selectSeller() + selectSeller({ selectedItem }) }, [selectedItem, selectSeller]) const className = currentSelectedItem diff --git a/react/hooks/useSelectSeller.ts b/react/hooks/useSelectSeller.ts index f6c73878..9b1a57ac 100644 --- a/react/hooks/useSelectSeller.ts +++ b/react/hooks/useSelectSeller.ts @@ -34,11 +34,16 @@ export const useSelectSeller = () => { [seller, product] ) - const selectSeller = () => { - if (!currentSelectedItem) { + const selectSeller = ({ + selectedItem, + }: { + selectedItem: Item | null | undefined + }) => { + if (!currentSelectedItem || !selectedItem) { return } + // just to keep the dependency setLoading(true) const { sellers } = (currentSelectedItem as unknown) as Item const selectedItemWithSeller = {