Added value reporting and fixed a cycle error

This commit is contained in:
Justin Edmund 2023-03-18 12:15:33 -07:00
parent a62db832eb
commit 18aa3d4a4e
3 changed files with 8 additions and 7 deletions

View file

@ -21,7 +21,8 @@ const InputTableField = (props: Props) => {
const [value, setValue] = useState(0) const [value, setValue] = useState(0)
useEffect(() => { useEffect(() => {
if (props.value) setValue(props.value) if (props.value !== undefined && props.value !== value)
setValue(props.value)
}, [props.value]) }, [props.value])
useEffect(() => { useEffect(() => {

View file

@ -9,7 +9,7 @@ interface Props {
name: string name: string
label: string label: string
description?: string description?: string
value?: number value: number
className?: string className?: string
imageAlt?: string imageAlt?: string
imageClass?: string imageClass?: string
@ -25,11 +25,11 @@ const SliderTableField = (props: Props) => {
useEffect(() => { useEffect(() => {
if (props.value !== undefined && props.value !== value) if (props.value !== undefined && props.value !== value)
if (props.value) setValue(props.value) setValue(props.value)
}, [props.value]) }, [props.value])
useEffect(() => { useEffect(() => {
if (value !== undefined && value !== props.value) props.onValueChange(value) props.onValueChange(value)
}, [value]) }, [value])
function handleValueCommit(value: number[]) { function handleValueCommit(value: number[]) {

View file

@ -8,7 +8,7 @@ interface Props {
name: string name: string
label: string label: string
description?: string description?: string
value?: boolean value: boolean
className?: string className?: string
imageAlt?: string imageAlt?: string
imageClass?: string imageClass?: string
@ -20,11 +20,11 @@ const SwitchTableField = (props: Props) => {
const [value, setValue] = useState(false) const [value, setValue] = useState(false)
useEffect(() => { useEffect(() => {
if (props.value) setValue(props.value) if (value !== props.value) setValue(props.value)
}, [props.value]) }, [props.value])
useEffect(() => { useEffect(() => {
if (value !== undefined) props.onValueChange(value) props.onValueChange(value)
}, [value]) }, [value])
function onValueChange(value: boolean) { function onValueChange(value: boolean) {