Skip to content

Commit

Permalink
fix: a useEffect Hook has been added to detect if the value received … (
Browse files Browse the repository at this point in the history
#339)

Co-authored-by: jared-dickman <[email protected]>
  • Loading branch information
nrmerlis and jared-dickman authored Jul 23, 2024
1 parent 9561a49 commit 0e1ab5d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/data-entry/QueryItem/Cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,20 @@ const Cascader = (props: ICascaderProps) => {
const [searchValue, setSearchValue] = useState('')
const [selectedValue, setSelectedValue] = useState<Array<number | string>>(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)

useEffect(() => {
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) {
Expand Down Expand Up @@ -179,4 +185,4 @@ const Cascader = (props: ICascaderProps) => {
}
}

export default Cascader
export default Cascader

0 comments on commit 0e1ab5d

Please sign in to comment.