mauricevancooten / react-anchor-link-smooth-scroll

React component for anchor links using the smooth scroll polyfill.
243 stars 31 forks source link

Crashes if target element is not present on the page #35

Closed joshuabaker closed 1 year ago

joshuabaker commented 4 years ago

If the element ($anchor) is not present the subsequent call to getBoundingClientRect() will throw an exception.

What’s your thoughts on wrapping this with a try...catch?

Exception

TypeError: Cannot read property 'getBoundingClientRect' of null

Source

https://github.com/mauricevancooten/react-anchor-link-smooth-scroll/blob/1f86d5e868e0b4efeb97a750b836561de3813226/src/anchor-link.js#L22-L23