From b54fdf78ee604707a6bab76da749bf01ff8fee37 Mon Sep 17 00:00:00 2001 From: Nicolas Merlis Date: Tue, 23 Jul 2024 13:43:36 -0300 Subject: [PATCH] fix: a useEffect Hook has been added to detect if the value received from parameter has changed --- src/components/data-entry/QueryItem/Cascader.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/data-entry/QueryItem/Cascader.tsx b/src/components/data-entry/QueryItem/Cascader.tsx index 821937982..d904fd4f8 100644 --- a/src/components/data-entry/QueryItem/Cascader.tsx +++ b/src/components/data-entry/QueryItem/Cascader.tsx @@ -38,7 +38,7 @@ const Cascader = (props: ICascaderProps) => { const [searchValue, setSearchValue] = useState('') const [selectedValue, setSelectedValue] = useState>(props.value ?? []) const [selectedDisplayValue, setSelectedDisplayValue] = useState( - props.value ? (props.value.slice(-1)[0] as any).label : '', + props.value && props.value.length > 0 ? (props.value.slice(-1)[0] as any).label : '', ) const [isOpen, setIsOpen] = useState(false) @@ -46,6 +46,12 @@ const Cascader = (props: ICascaderProps) => { setItems(props.options) }, [props.options]) + useEffect(() => { + if (props.value && props.value.length > 0) { + setSelectedValue(props.value) + } + }, [props.value]) + const onSearch = ({ target: { value } }: { target: { value: string } }) => { if (debouncedLoadData) { if (value.length > 3) { @@ -179,4 +185,4 @@ const Cascader = (props: ICascaderProps) => { } } -export default Cascader \ No newline at end of file +export default Cascader