Skip to content

useAutoScroll ​

Hook that automatically scrolls a list element to the bottom

elements
test coverage
Last changed: 2 days ago

Installation ​

Library
CLI
Manual
typescript
import { useAutoScroll } from '@siberiacancode/reactuse';

Usage ​

typescript
useAutoScroll(ref);
// or
const ref = useAutoScroll();

Demo ​

Api ​

Parameters

NameTypeDefaultNote
targetHookTarget-The target element to auto-scroll
options.enabled?boolean-Whether auto-scrolling is enabled

Returns

void

Parameters

NameTypeDefaultNote
options.enabled?boolean-Whether auto-scrolling is enabled

Returns

StateRef<Target>

Type declaration ​

typescript
import type { HookTarget } from '@/utils/helpers';

import type { StateRef } from '../useRefState/useRefState';

export interface UseAutoScrollOptions {
  /** Whether auto-scrolling is enabled */
  enabled?: boolean;
  /** Whether to force auto-scrolling regardless of user interactions */
  force?: boolean;
}

export interface UseAutoScroll {
  (target: HookTarget, options?: UseAutoScrollOptions): void;

  <Target extends HTMLElement>(options?: UseAutoScrollOptions): StateRef<Target>;
}

Source ​

Source • Demo

Contributors ​

D
debabin
debabin

Released under the MIT License.