From d5f0e3532a6671f3b167e3a22ad8cfb2bc7f4755 Mon Sep 17 00:00:00 2001 From: Sofiya Tepikin Date: Tue, 20 Sep 2022 15:32:47 +0000 Subject: [PATCH] Fix useEffect callback cannot be async --- components/chart/chart.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/components/chart/chart.js b/components/chart/chart.js index 6b07629..3cdd364 100644 --- a/components/chart/chart.js +++ b/components/chart/chart.js @@ -31,9 +31,21 @@ const getSymptomsFromCycleDays = (cycleDays) => const CycleChart = ({ navigate, setDate }) => { const [shouldShowHint, setShouldShowHint] = useState(true) - useEffect(async () => { - const flag = await getChartFlag() - setShouldShowHint(flag === 'true') + useEffect(() => { + let isMounted = true + + async function checkShouldShowHint() { + const flag = await getChartFlag() + if (isMounted) { + setShouldShowHint(flag === 'true') + } + } + + checkShouldShowHint() + + return () => { + isMounted = false + } }, []) const hideHint = () => {