Skip to content

Commit f69e580

Browse files
committed
chore: add comments in useStickyEvent
1 parent 81e575a commit f69e580

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Shared/Hooks/useStickyEvent/useStickyEvent.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ const useStickyEvent = <T extends HTMLElement = HTMLDivElement>({
3737
return noop
3838
}
3939

40-
// NOTE: these values are being used as closures
40+
// The sentinel is a div used to detect when the sticky element is stuck.
41+
// It is taller than the sticky element's top offset, ensuring it overflows
42+
// the container when the sticky element sticks to the top.
43+
// Using IntersectionObserver, we observe both the sticky element and the sentinel.
44+
// When the sentinel is not fully in view, isIntersecting is false,
45+
// indicating the sticky element is stuck given it is fully in view.
4146
let previousStuckState: boolean
4247
let hasSentinelLeftView: boolean
4348
let hasHeaderLeftView: boolean
@@ -49,6 +54,10 @@ const useStickyEvent = <T extends HTMLElement = HTMLDivElement>({
4954
entries.forEach((entry) => {
5055
switch (entry.target.id) {
5156
case sentinelId:
57+
// NOTE: Since the threshold is set to 1.0, isIntersecting will be
58+
// true only when the target element is fully within the container
59+
// (root). If even a single pixel of the target element is outside
60+
// the container, isIntersecting will be false.
5261
hasSentinelLeftView = !entry.isIntersecting
5362
break
5463
default:

0 commit comments

Comments
 (0)