# react-scrollwatch

> React higher order component (HOC) for reacting to when a component comes into view

Latest version **1.0.1** (published 2017-06-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-scrollwatch
pnpm add react-scrollwatch
yarn add react-scrollwatch
bun add react-scrollwatch
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-06-07 |
| First published | 2017-06-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Joshua Purcell |
| Maintainers | vuldin |
| Keywords | react, component, hoc, scroll, react-component |

## Links

- npm: https://www.npmjs.com/package/react-scrollwatch
- Repository: https://github.com/vuldin/react-scrollwatch
- Issues: https://github.com/vuldin/react-scrollwatch/issues
- npm.io page: https://npm.io/package/react-scrollwatch

## 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

- 1.0.1 (latest) — 2017-06-07
- 1.0.0 — 2017-06-06

## README

# react-scrollwatch

[![Travis][build-badge]][build]
[![npm package][npm-badge]][npm]
[![Coveralls][coveralls-badge]][coveralls]

## Motivation
There are a couple of existing libraries for handling scroll events: [scrollwatch](https://github.com/edull24/ScrollWatch) and [react-component-visibility](https://github.com/Pomax/react-component-visibility).
However neither of these worked well in modern [react](https://facebook.github.io/react/) projects.

`react-scrollwatch` is a simple higher order component (HOC) that makes reacting to when a components shows up in the viewport.

## Browser only
This module depends on a browser environment with `document` and `window`.
Other environments such as those available through React Native is not currently supported.

## Install
```bash
npm i -S react-scrollwatch
```

## Usage
`react-scrollwatch` relies on [nwb](https://github.com/insin/nwb).
This is mainly for packaging into various types of npm-ready modules (compatible with UMD, CommonJS, ES5, and ES6).
Run the example to see this component in action:
```bash
git clone https://github.com/vuldin/react-scrollwatch.git
cd react-scollwatch
npm i -g nwb
npm i
npm start
```
Open [http://localhost:3000](http://localhost:3000) and scroll down the page to see a div change background color when in view.

## Properties
All properties are optional.
- **shownPercent** (default: `'50%'`): percentage of the div that needs to be shown from either side before being considerd 'shown'
- **throttle** (default: `250`): milliseconds to wait between listening for one of the following listeners:
  1. visibilitychange (on document)
  2. scroll (on document)
  3. resize (on window)
- **onShown** (default: function `undefined`): if defined this function will be passed the JSON version of the style from the wrapped component once it is considered visible.
- **onHidden** (default: function `undefined`): if defined this function will be passed the JSON version of the style from the wrapped component once it is considered hidden.
- *style properties* (default: none): Pass any css styles you wish as properties to this higher order component... they will be applied as inline styled to the wrapped component.

# Guidelines
- *This HOC must wrap a React component.* Normal elements will result in an error.

## Testing
While testing is built in to this project (thanks to [nwb](https://github.com/insin/nwb)!) I have not yet created tests. *Check back later!*

[build-badge]: https://img.shields.io/travis/vuldin/react-scrollwatch/master.png?style=flat-square
[build]: https://travis-ci.org/vuldin/react-scrollwatch

[npm-badge]: https://img.shields.io/npm/v/npm-package.png?style=flat-square
[npm]: https://www.npmjs.org/package/react-scrollwatch

[coveralls-badge]: https://img.shields.io/coveralls/vuldin/react-scrollwatch/master.png?style=flat-square
[coveralls]: https://coveralls.io/github/vuldin/react-scrollwatch

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