0

I'd like to use intersection observer in my React TS project.

(https://www.npmjs.com/package/react-intersection-observer)

At one point I cannot set the root:

const root = useRef(null);

const { ref, inView, entry } = useInView({
     root: root,
     threshold: 0,
     onChange: () => console.log(inView)
});

At this point the root option gives this error:

Type 'MutableRefObject<null>' is missing the following properties from type 'Element': attributes, classList, className, clientHeight, and 164 more.ts(2740)

Can I set the root with ref?

Bufer
  • 85
  • 1
  • 8
  • Can you try `const root = useRef(null);`? Don't forget to set ref to Element and check if it's set when you use it. – Matija Sirk Jan 17 '23 at 13:37
  • Basically same: Type 'MutableRefObject' is missing the following properties from type 'Element': attributes, classList, className, clientHeight, and 164 more.ts(2740) – Bufer Jan 17 '23 at 15:18

0 Answers0