I need to check the textAreaRef.current
and textAreaRef.current.resizableTextArea
for undefined
value.
That works:
if (textAreaRef.current && textAreaRef.current.resizableTextArea) {
const currentCursorPosition = textAreaRef.current.resizableTextArea.textArea.selectionStart;
}
But that don’t:
function isTextAreaExists() {
return textAreaRef.current && textAreaRef.current.resizableTextArea;
}
if (isTextAreaExists()) {
const currentCursorPosition = textAreaRef.current.resizableTextArea.textArea.selectionStart;
}
TS18047: textAreaRef.current is possibly null
TS18048: textAreaRef.current.resizableTextArea is possibly null
Are there ways to simplify the expression?