hook to know if a element is on the screen
npm install use-in-screen
import useInScreen from "use-in-screen";
const isInViewport = useInScreen(element);
`
With REACT ā !!!
`
import React, { useState, useRef } from "react"
import useInScreen from "use-in-screen";
function MyComponent() {
const element = useRef(null)
const isInViewport = useInScreen(element);
return (
this div {isInViewport ? "is" : "is not"} on screen
)
}
``