From e4f29efbd2d68d4589c57261f77a61b013983e8e Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Thu, 27 Jul 2023 19:01:16 +0100 Subject: [PATCH] Added state setting of default index --- src/app/components/building-passport/RecommendationCard.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/app/components/building-passport/RecommendationCard.tsx b/src/app/components/building-passport/RecommendationCard.tsx index fb06508..52f8575 100644 --- a/src/app/components/building-passport/RecommendationCard.tsx +++ b/src/app/components/building-passport/RecommendationCard.tsx @@ -56,7 +56,9 @@ export function RecommendationModal({ const [saveButtonDisabled, setSaveButtonDisabled] = useState(true); // Find the row where default is true - const defaultRowIndex = recommendationData.findIndex((d) => d.default); + const [defaultRowIndex, setDefaultRowIndex] = useState( + recommendationData.findIndex((d) => d.default) + ); // Initialise the state with the default row index const [rowSelection, setRowSelection] = useState( @@ -78,6 +80,8 @@ export function RecommendationModal({ const newIndex = parseInt(Object.keys(rowSelection)[0]); setCardComponent(recommendationData[newIndex]); + // Set the default index + setDefaultRowIndex(newIndex); } return (