# react-in-view

> Add in/exit event hook when a react component enter/leave.

Latest version **1.0.0** (published 2017-09-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-in-view
pnpm add react-in-view
yarn add react-in-view
bun add react-in-view
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-09-08 |
| First published | 2017-09-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ssruoyan |
| Maintainers | ssruoyan |
| Keywords | react, in, view |

## Links

- npm: https://www.npmjs.com/package/react-in-view
- Repository: https://github.com/ssruoyan/react-inview
- Homepage: https://github.com/ssruoyan/react-inview#readme
- Issues: https://github.com/ssruoyan/react-inview/issues
- npm.io page: https://npm.io/package/react-in-view

## Dependencies (2)

- [react](https://npm.io/package/react.md) ^15.6.1
- [react-dom](https://npm.io/package/react-dom.md) ^15.6.1

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@pandacss/eslint-plugin](https://npm.io/package/@pandacss/eslint-plugin.md) — 18.7K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2017-09-08

## README

# react-inview
Add in/exit viewport event hook on react components


# install
install with npm

> npm install --save react-in-view

# how to use
```
import React, { Component } from 'react'
import InView from 'react-in-view'

class App extends Component {
  constructor(props) {
    super(props)
    this.state = {
      text: '',
      visible: false,
    }

    this.handleEnter = this.handleEnter.bind(this)
    this.handleLeave = this.handleLeave.bind(this)
  }
  handleEnter() {
    this.setState({
      text: '进来了',
      visible: true,
    })
  }
  handleLeave() {
    this.setState({
      text: '出去了',
      visible: false,
    })
  }
  render() {
    const { text, visible } = this.state
    const style = {
      position: 'fixed',
      top: 0,
      width: '100%',
      height: '40px',
      opacity: visible ? 1 : 0,
      lineHeight: '40px',
      color: '#fff',
      textAlign: 'center',
      transition: 'all 300ms ease-in-out',
      background: 'black'
    }
    const sectionStyle = {
      height: '200px',
      background: 'red',
      marginTop: '100px'
    }

    return (
      <div>
        <div style={{height: '1000px'}}></div>
        <div style={style}>顶部导航</div>
        <ReactInView onEnter={this.handleEnter} onLeave={this.handleLeave} thresholdY={0.5}>
          <div style={sectionStyle} className="in-view">
            {this.state.text}
          </div>
        </ReactInView>
        <div style={{height: '1000px'}}></div>
      </div>
    )
  }
}
```

#received props

| 属性名 | 描述信息 | 默认值 | 类型
--- | --- | --- | ---
onLeave | trigger when element leave viewport | | Function
onEnter | trigger when element enter viewport | | Function
thresholdX | set enter/leave threshold rate that relative to the element width. | 0 | Number
thresholdY | set enter/leave threshold rate that relative to the element height. | 0 | Number
offsetTop | set enter/leave threshold value that offset window top | 0 | Number
offsetBottom | set enter/leave threshold value that offset window bottom | 0 | Number
offsetRight | set enter/leave threshold value that offset window right | 0 | Number
offsetLeft | set enter/leave threshold value that offset window left | 0 | Number

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