You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
useScrollSpy: accept a RefObject<HTMLElement> for scrollHost, not just a resolved HTMLElement #9025
Currently scrollHost only accepts a resolved HTMLElement:
exportinterfaceUseScrollSpyOptions{/** Host element to attach scroll event listener, if not provided, `window` is used */scrollHost?: HTMLElement;// ...}
The idiomatic way to obtain a DOM node in React is a ref (useRef / callback ref). But a ref's .current isn't populated on first render and mutating it doesn't trigger a re-render, so passing scrollHostRef.current to the hook gives undefined on mount and the hook never re-initializes when the node attaches.
The current workaround is to convert the element into state via a callback ref, purely so the hook re-runs once the host exists:
This is backwards-compatible — existing HTMLElement callers are unaffected — and mirrors patterns elsewhere in Mantine where hooks accept refs.
Possible implementation
Internally, narrow the prop: if it's a ref ('current' in scrollHost), read .current; otherwise use it directly. The existing initialization useEffect already keys off scrollHost, so it would just need the resolved node in its dependency/closure.
Activity
[@mantine/hooks] use-scroll-spy: Allow usage with refs (#9025)
rtivital commentedon Aug 2, 2026
Added in 9.5.1