Overview
useInView returns a boolean indicating whether the referenced element is currently in the viewport. It uses the Intersection Observer API under the hood.
Import
Signature
Parameters
ref (required)
A React ref attached to the element to observe.root
A ref to the scrolling container. If not provided, uses the viewport.margin
Margin around the root element. Similar to CSS margin property."0px"(all sides)"0px 0px"(vertical horizontal)"0px 0px 0px 0px"(top right bottom left)
amount
How much of the element must be visible to trigger."some": Any part of the element is visible"all": The entire element must be visiblenumber: A value between 0 and 1 representing the percentage
once
Iftrue, the element will remain “in view” after it first enters the viewport.