From 388e8ff49e158335e72d217fd18c5b8fd9359d02 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Sat, 18 Mar 2023 12:53:25 -0700 Subject: [PATCH] Fix maximum cycle depth exceeded error --- components/InputTableField/index.tsx | 6 ++---- components/SliderTableField/index.tsx | 14 +++++--------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/components/InputTableField/index.tsx b/components/InputTableField/index.tsx index 315db50b..c7a254cb 100644 --- a/components/InputTableField/index.tsx +++ b/components/InputTableField/index.tsx @@ -9,7 +9,7 @@ interface Props { label: string description?: string placeholder?: string - value?: number + value: number className?: string imageAlt?: string imageClass?: string @@ -21,8 +21,7 @@ const InputTableField = (props: Props) => { const [value, setValue] = useState(0) useEffect(() => { - if (props.value !== undefined && props.value !== value) - setValue(props.value) + if (props.value) setValue(props.value) }, [props.value]) useEffect(() => { @@ -44,7 +43,6 @@ const InputTableField = (props: Props) => { > { - const [value, setValue] = useState(0) + const [value, setValue] = useState(props.value) useEffect(() => { if (props.value !== undefined && props.value !== value) @@ -29,7 +29,7 @@ const SliderTableField = (props: Props) => { }, [props.value]) useEffect(() => { - props.onValueChange(value) + if (value !== props.value) props.onValueChange(value) }, [value]) function handleValueCommit(value: number[]) { @@ -40,14 +40,10 @@ const SliderTableField = (props: Props) => { setValue(value[0]) } - function onInputChange(event: React.ChangeEvent) { + function handleInputChange(event: React.ChangeEvent) { setValue(parseInt(event.currentTarget?.value)) } - function onValueChange(value: number[]) { - setValue(value[0]) - } - return ( { max={props.max} step={props.step} value={[value]} - onValueChange={onValueChange} + onValueChange={handleValueChange} onValueCommit={handleValueCommit} /> { min={props.min} max={props.max} step={props.step} - onChange={onInputChange} + onChange={handleInputChange} /> )