Skip to content
On this page

useScroll

Get the scroll position of an element.

Code demonstration

Basic Usage

Detect Whole Page Scroll

Control listen on scroll status

API

const position = useScroll(target, shouldUpdate)
const position = useScroll(target, shouldUpdate)

Params

PropertyDescriptionTypeDefault
targetDOM element or ref objectElement | Document | (() => Element) | JSX.Elementdocument
shouldUpdateWhether update position({ top: number, left: number }) => boolean-

Result

PropertyDescriptionType
positionThe current scroll position of the element.Readonly<Ref<{ left: number, top: number } | undefined>>

Source

SourceDocsDemo