According to other similar issues about this type of error with TypeScript (on questions #44147937 and #40796374) I've found that assigning null
to create a state or reference will cause this problem:
Property ... does not exist on type 'never'
how to handle this issue in this example component?
const FooComponent: FunctionComponent<FooInterface> = () => {
const myRef = useRef(null)
const handleClickOnButton = () => myRef?.current?.click();
return (
<div>
<div ref={myRef} />
<button onClick={handleClickOnButton} />
</div>
}