Fix undefined value case

This commit is contained in:
Rafael 2022-04-25 14:21:54 -03:00 committed by Thomas Zarebczan
parent 5787bfcf2f
commit 7390c464ac

View file

@ -90,7 +90,7 @@ export default function TextareaWithSuggestions(props: Props) {
placeholder,
searchQuery,
type,
value: messageValue,
value: messageValue = '',
autoFocus,
submitButtonRef,
spellCheck,
@ -274,14 +274,17 @@ export default function TextareaWithSuggestions(props: Props) {
if (!suggestionValue) return;
const elem = inputRef && inputRef.current;
// $FlowFixMe
const newCursorPos = suggestionValue.beforeTerm.length + suggestionValue.index + selectedValue.length + 1;
// $FlowFixMe
const contentBegin = messageValue.substring(0, suggestionValue.index);
// $FlowFixMe
const replaceValue = suggestionValue.beforeTerm + selectedValue;
const contentEnd =
messageValue.length > suggestionValue.lastIndex
? messageValue.substring(suggestionValue.lastIndex, messageValue.length)
: ' ';
// $FlowFixMe
const endTo = messageValue.substring(suggestionValue.lastIndex, messageValue.length);
// $FlowFixMe
const contentEnd = messageValue.length > suggestionValue.lastIndex ? endTo : ' ';
const newValue = contentBegin + replaceValue + contentEnd;