Skip to content

Instantly share code, notes, and snippets.

View markwybrow's full-sized avatar
:octocat:

Mark Wybrow markwybrow

:octocat:
View GitHub Profile

The hook

useScrollPosition.js:

import { useRef, useLayoutEffect } from 'react'

const isBrowser = typeof window !== `undefined`

function getScrollPosition({ element, useWindow }) {