Skip to content

useAutoScroll

Hook that automatically scrolls a list element to the bottom

elements
low
test coverage
Last changed: 24 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

{ ref: 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
  ): {
    ref: StateRef<Target>;
  };
}

Source

SourceDemo

Contributors

D
debabin
debabin

Released under the MIT License.