Skip to content

Commit

Permalink
fix: handle optional chaining for offsetTop in scroll.ts
Browse files Browse the repository at this point in the history
Refactor the code in scroll.ts to handle optional chaining (?.) for the offsetTop property. This ensures that the code doesn't throw an error when ref.current is null or undefined. The offsetTop value is used in the calculation of scrollPositionRelativeToRef. This fix addresses a potential bug where the code could break if ref.current is not available.
  • Loading branch information
schettn authored Jun 10, 2024
1 parent 1ac985c commit 0d0042b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/hooks/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const useScrollShow = (

const scrollPositionRelativeToRef =
target.documentElement.scrollTop -
(offsetTop ? offsetTop : ref.current!.offsetTop) -
(offsetTop ? offsetTop : ref.current?.offsetTop || 0) -
(noScroll ? 999999999 : offset)

if (!display && scrollPositionRelativeToRef >= 0) {
Expand Down

0 comments on commit 0d0042b

Please sign in to comment.