# react-auto-scroll-container

> ReactAutoScrollContainer is a React component designed to automatically scroll to the bottom when new content is added and the user is already at the container's bottom. This feature is especially handy for real-time or dynamic content updates.

Latest version **0.2.1** (published 2024-12-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-auto-scroll-container
pnpm add react-auto-scroll-container
yarn add react-auto-scroll-container
bun add react-auto-scroll-container
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2024-12-04 |
| First published | 2023-11-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 19 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ruifeng Zhang |
| Maintainers | failury |
| Keywords | react, typescript, autoscroll, scroll |

## Links

- npm: https://www.npmjs.com/package/react-auto-scroll-container
- Repository: https://github.com/failury/react-auto-scroll-container
- Homepage: https://github.com/failury/react-auto-scroll-container#readme
- Issues: https://github.com/failury/react-auto-scroll-container/issues
- npm.io page: https://npm.io/package/react-auto-scroll-container

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.6.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.2.1 (latest) — 2024-12-04
- 0.2.0 — 2024-12-02
- 0.1.5 — 2024-12-02
- 0.1.4 — 2023-11-18
- 0.1.3 — 2023-11-18
- 0.1.2 — 2023-11-18
- 0.1.1 — 2023-11-03
- 0.1.0 — 2023-11-03

## README

# react-auto-scroll-container

ReactAutoScrollContainer is a React component designed to automatically scroll to the bottom when new content is added and the user is already at the container's bottom. This feature is especially handy for real-time or dynamic content updates.

## Installation

You can install `react-auto-scroll-container` using npm:

```bash
npm i react-auto-scroll-container
```
![Screen Recording 2024-12-04 at 10 22 25](https://github.com/user-attachments/assets/f494790e-5881-49d3-b901-565cc0aa809a)

## Example

[StackBlitz](https://stackblitz.com/edit/stackblitz-starters-jklubu?file=src%2FApp.tsx)

## Usage

```jsx
import React from 'react';
import {AutoScrollContainer} from 'react-auto-scroll-container';

const App = () => {
  return (
    <AutoScrollContainer active={true} percentageThreshold={10} style={{/* Your inline styles goes here */}} className="Your css classes goes here">
      {/* Your dynamic content goes here */}
    </AutoScrollContainer>
  );
};

export default App;
```

## Props

| Prop                    | Type                                                     | Default       | Description                                                                                                                                     |
| ----------------------- | -------------------------------------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| `children`            | `React.ReactNode`                                      | Required      | The content to be displayed within the scroll container                                                                                         |
| `percentageThreshold` | `number`                                               | `20`        | Defines the percentage of container height from bottom where auto-scrolling triggers. Lower values mean scrolling triggers closer to the bottom |
| `className`           | `string`                                               | `undefined` | CSS class name(s) to apply to the container                                                                                                     |
| `style`               | `CSSProperties`                                        | `undefined` | Inline styles to apply to the container                                                                                                         |
| `behavior`            | `string`                                               | `"auto"`    | Scroll behavior. Can be "auto", "smooth", or "instant"                                                                                          |
| `active`              | `boolean`                                              | `false`     | When true, enables auto-scrolling when new content is added                                                                                     |
| `forceScroll`         | `boolean`                                              | `false`     | When true, forces scrolling to bottom regardless of user's scroll position                                                                      |
| `overflowY`           | `"auto" \| "scroll" \| "hidden" \| "visible" \| "inherit"` | `"auto"`    | Controls vertical overflow behavior of the container                                                                                            |
| `as`                  | `React.ElementType`                                    | `"div"`     | The HTML element or component to render as the container                                                                                        |

### Example Usage with Props

```jsx
import React from 'react';
import {AutoScrollContainer} from 'react-auto-scroll-container';

const App = () => {
  return (
    <AutoScrollContainer percentageThreshold={10} style={{/* Your inline styles goes here */}} className="Your css classes goes here">
      {/* Your dynamic content goes here */}
    </AutoScrollContainer>
  );
};

export default App;
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

---
_Source: https://npm.io/package/react-auto-scroll-container · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
