this is how refs work. it's the same with a div. the ref will be filled in useEffect, not before.
null! is a common typescript thing, it is a semantic guarantee that the ref is static and hence will be available. this saves you the if (ref.current) { ... } check.