useScrollIntoView ​
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
Name | Type | Default | Note |
---|---|---|---|
target | Target | - | 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 |
Returns
Parameters
Name | Type | Default | Note |
---|---|---|---|
options.behavior? | ScrollBehavior | 'smooth' | The scrolling behavior |
options.block? | ScrollLogicalPosition | 'start' | The vertical alignment |
options.inline? | ScrollLogicalPosition | 'nearest' | The horizontal alignment |