Skip to content

Commit

Permalink
[GEN-1976]: fix "loading" for source conditions (#1969)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
BenElferink authored Dec 10, 2024
1 parent 3bf7a7c commit d2f2328
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ const Row = styled.div`
`;

export const ConditionDetails: React.FC<Props> = ({ 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';
Expand Down

0 comments on commit d2f2328

Please sign in to comment.