From d2f2328e272c09a0c74fd04903252c2533eb65e1 Mon Sep 17 00:00:00 2001 From: Ben Elferink Date: Tue, 10 Dec 2024 17:23:38 +0200 Subject: [PATCH] [GEN-1976]: fix "loading" for source conditions (#1969) This pull request includes a change to the `ConditionDetails` component in the `frontend/webapp/reuseable-components/condition-details/index.tsx` file. The change optimizes the `loading` state by using the `useMemo` hook instead of `useState`. Optimization: * [`frontend/webapp/reuseable-components/condition-details/index.tsx`](diffhunk://#diff-8ddad4625b70db190b926980070c30fb0c429fb2c13be252bba2c6de1e8cef4dL44-R46): Replaced the `useState` hook with the `useMemo` hook for the `loading` state to improve performance by memoizing the value based on the `conditions` array. --- .../webapp/reuseable-components/condition-details/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/webapp/reuseable-components/condition-details/index.tsx b/frontend/webapp/reuseable-components/condition-details/index.tsx index b3fb60e2a..5d3baabec 100644 --- a/frontend/webapp/reuseable-components/condition-details/index.tsx +++ b/frontend/webapp/reuseable-components/condition-details/index.tsx @@ -41,9 +41,9 @@ const Row = styled.div` `; export const ConditionDetails: React.FC = ({ conditions }) => { - const [loading, setLoading] = useState(false); const [extend, setExtend] = useState(false); + const loading = useMemo(() => !conditions.length, [conditions]); const errors = useMemo(() => conditions.filter(({ status }) => status === BACKEND_BOOLEAN.FALSE), [conditions]); const hasErrors = !!errors.length; const headerText = loading ? 'Loading...' : hasErrors ? 'Operation Failed' : 'Operation Successful';