Having issue with useRef
Unanswered
Great Skua posted this in #help-forum
Great SkuaOP
I have useRef
and I have this function
Why I can just use the
It says
const newWishlistInputRef = useRef<HTMLInputElement | null>(null);and I have this function
const submitNewTaskHandler = (event: FormEvent) => {
event.preventDefault();
if (newWishlistInputRef.current) {
addWishlistToArr({
id: nextId,
text: capitalizeFirstCharacter(newWishlistInputRef.current.value),
isEditMode: false
})
newWishlistInputRef.current.value = '';
newWishlistInputRef.current.focus();
}
}Why I can just use the
newWishlistInputRef.current.value without the if (newWishlistInputRef.current) {?It says
'newWishlistInputRef.current' is possibly 'null'.ts(18047)