DEV Community

Discussion on: How to fade in content as it scrolls into view

Collapse
 
victoruvarov profile image
Victor Uvarov

Thanks I figured it out already. There were 3 problems.

  • useRef() should be initialized with null and typed.
const domRef = useRef<HTMLDivElement>(null);
  • the ref will be null for a second, so I just needed to have a local var in the first lines of the effect
const current = domRef.current;
if (!current) return;