score:2

Accepted answer

refs can be null on rerenders therefore always null check before accesssing properties of elements refs. here is what gaearon has to say about refs.

const handlescroll = () => {
      if(!ref.current) return
      if (ref.current.getboundingclientrect().y <= -580 || null) {
        console.log(ref.current.getboundingclientrect().y);

        setsticky(true);
      } else {
        setsticky(false);
      }
    };

score:0

sorry for writing late.

if(status: solved)
{
  **congratulations**
}

else{

well, i guess the problem is not in your js file, maybe it is in your .html file. go there and either use defer where u linked your js file or put it under your targeted element. that might work, at least it did for me! }


Related Query

More Query from same tag