From 1ea94581449df0d6de9df7bc331f1d125872eafc Mon Sep 17 00:00:00 2001 From: Zafir Rasyidi Taufik <zafir.r.taufik@gmail.com> Date: Sun, 25 Apr 2021 22:53:24 +0700 Subject: [PATCH] [REFACTOR/CHORES]Made setActiveIndexHelper to keep smooth rendering but not repeat self too much --- .../Home/components/Statistic/index.tsx | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/scenes/Home/components/Statistic/index.tsx b/src/scenes/Home/components/Statistic/index.tsx index a0db5c1..4375168 100644 --- a/src/scenes/Home/components/Statistic/index.tsx +++ b/src/scenes/Home/components/Statistic/index.tsx @@ -110,6 +110,16 @@ function Statistic({ } }; + const setActiveIndexHelper = async (tempData: StatisticData) => { + let res: Array<number> = []; + tempData.parts.forEach((element, index) => { + if(element.jumlah > 0) { + res.push(index); + } + }); + setActiveIndex(res); + } + useEffect(() => { const tempAgeObject = { positive: 0, @@ -138,6 +148,7 @@ function Statistic({ ] }; setselectedKeyData(tempData); + setActiveIndexHelper(tempData); }, [data, ageKey]); useEffect(() => { @@ -151,18 +162,9 @@ function Statistic({ ], }; setselectedKeyData(tempData); + setActiveIndexHelper(tempData); }, [data, selectedKey]); - useEffect(() => { - let res: Array<number> = []; - selectedKeyData.parts.forEach((element, index) => { - if(element.jumlah > 0) { - res.push(index); - } - }); - setActiveIndex(res); - }, [selectedKeyData]); - useEffect(() => { const parsedData: string[][] = []; for (const key of Object.keys(data)) { -- GitLab