Skip to content

Cannot read property 'getBoundingClientRect' of null #36

@saadaouad

Description

@saadaouad

First of all I'd like to thank you for this package,

I'm getting this error raised on Sentry:

TypeError apply(react-anchor-link-smooth-scroll/lib/anchor-link) error 
Cannot read property 'getBoundingClientRect' of null

Screen Shot 2020-11-10 at 1 18 41 PM

And I think it would be great to silent it by providing $anchor var with something like this:

var $anchor = document.getElementById(id);
var offsetTop = $anchor && $anchor.getBoundingClientRect().top + window.pageYOffset;

Or use optional chaining:

var $anchor = document?.getElementById(id);
var offsetTop = $anchor?.getBoundingClientRect().top + window.pageYOffset;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions