Skip to content

useScrollIntoView ​

Category
Sensors

Hook that provides functionality to scroll an element into view

typescript
import { useScrollIntoView } from '@siberiacancode/reactuse';

Usage ​

typescript
const { trigger } = useScrollIntoView(ref);
// or
const { ref, trigger } = useScrollIntoView<HTMLDivElement>();

Demo ​

Api ​

Parameters

NameTypeDefaultNote
targetTarget-The target element to scroll into view
options.behavior?ScrollBehavior'smooth'The scrolling behavior
options.block?ScrollLogicalPosition'start'The vertical alignment
options.inline?ScrollLogicalPosition'nearest'The horizontal alignment

Parameters

NameTypeDefaultNote
options.behavior?ScrollBehavior'smooth'The scrolling behavior
options.block?ScrollLogicalPosition'start'The vertical alignment
options.inline?ScrollLogicalPosition'nearest'The horizontal alignment

Contributors ​

Source • Demo