From 9802c731fb391ec43d354cd94fc4a74d55c7c64d Mon Sep 17 00:00:00 2001 From: Daniil Palagin Date: Tue, 22 Oct 2024 14:05:44 +0200 Subject: [PATCH] [#365] Fix `Cannot read length property in Storybook` error --- src/components/answer/TypeaheadAnswer.jsx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/components/answer/TypeaheadAnswer.jsx b/src/components/answer/TypeaheadAnswer.jsx index 515e5ac2..8dd6e871 100644 --- a/src/components/answer/TypeaheadAnswer.jsx +++ b/src/components/answer/TypeaheadAnswer.jsx @@ -14,7 +14,7 @@ import { IntelligentTreeSelect } from "intelligent-tree-select/lib/components/In import "intelligent-tree-select/lib/styles.css"; const processTypeaheadOptions = (options, intl) => { - if (!options || !options.length) { + if (options === undefined || !options.length) { return []; } @@ -41,9 +41,9 @@ const TypeaheadAnswer = (props) => { const intl = configurationContext.options.intl; const [isLoading, setLoading] = useState(true); - const [optionsList, setOptionsList] = useState([ - processTypeaheadOptions(props.options, intl), - ]); + const [optionsList, setOptionsList] = useState( + processTypeaheadOptions(props.options, intl) + ); useEffect(() => { let isCancelled = false; @@ -79,7 +79,7 @@ const TypeaheadAnswer = (props) => { return () => { isCancelled = true; }; - }, []); + }, [queryHash, formGenContext, props.question, intl]); const generateTreeOptions = (possibleValues) => { if (!possibleValues) { @@ -169,8 +169,7 @@ const TypeaheadAnswer = (props) => { ? noLinksValueRenderer : null } - valueIsControlled={true} - value={optionsList.filter((option) => option.id === props.value)} + value={optionsList.find((option) => option.id === props.value) || null} multi={false} options={optionsList} isSearchable={true}