I\'ve got the \"Object is possibly null\" error many times and usually I use a safety \"if statement\" in case it returns null.
I\'ve got the following function:
const overlayEl = useRef() as MutableRefObject;
It will cast overlayEl to an initiated MutableRefObject that is the returning value of useRef:
overlayEl
useRef
function useRef(): MutableRefObject;
Yet in this case, the compiler will always think that overlayEl has a value.