From 18aa3d4a4e9e5c0f8286aedd028da7242595b408 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 18 Mar 2023 12:15:33 -0700 Subject: [PATCH] Added value reporting and fixed a cycle error --- components/InputTableField/index.tsx | 3 ++- components/SliderTableField/index.tsx | 6 +++--- components/SwitchTableField/index.tsx | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/components/InputTableField/index.tsx b/components/InputTableField/index.tsx index c3fd1349..315db50b 100644 --- a/components/InputTableField/index.tsx +++ b/components/InputTableField/index.tsx @@ -21,7 +21,8 @@ const InputTableField = (props: Props) => { const [value, setValue] = useState(0) useEffect(() => { - if (props.value) setValue(props.value) + if (props.value !== undefined && props.value !== value) + setValue(props.value) }, [props.value]) useEffect(() => { diff --git a/components/SliderTableField/index.tsx b/components/SliderTableField/index.tsx index 07f86ff1..f3742bdb 100644 --- a/components/SliderTableField/index.tsx +++ b/components/SliderTableField/index.tsx @@ -9,7 +9,7 @@ interface Props { name: string label: string description?: string - value?: number + value: number className?: string imageAlt?: string imageClass?: string @@ -25,11 +25,11 @@ const SliderTableField = (props: Props) => { useEffect(() => { if (props.value !== undefined && props.value !== value) - if (props.value) setValue(props.value) + setValue(props.value) }, [props.value]) useEffect(() => { - if (value !== undefined && value !== props.value) props.onValueChange(value) + props.onValueChange(value) }, [value]) function handleValueCommit(value: number[]) { diff --git a/components/SwitchTableField/index.tsx b/components/SwitchTableField/index.tsx index 6163d919..e2e2e2bd 100644 --- a/components/SwitchTableField/index.tsx +++ b/components/SwitchTableField/index.tsx @@ -8,7 +8,7 @@ interface Props { name: string label: string description?: string - value?: boolean + value: boolean className?: string imageAlt?: string imageClass?: string @@ -20,11 +20,11 @@ const SwitchTableField = (props: Props) => { const [value, setValue] = useState(false) useEffect(() => { - if (props.value) setValue(props.value) + if (value !== props.value) setValue(props.value) }, [props.value]) useEffect(() => { - if (value !== undefined) props.onValueChange(value) + props.onValueChange(value) }, [value]) function onValueChange(value: boolean) {