# @nju33/react-intersection-observed

> wip

Latest version **0.1.31** (published 2018-02-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @nju33/react-intersection-observed
pnpm add @nju33/react-intersection-observed
yarn add @nju33/react-intersection-observed
bun add @nju33/react-intersection-observed
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.31 |
| Published | 2018-02-17 |
| First published | 2018-02-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | nju33 |
| Keywords | intersection, observer |

## Links

- npm: https://www.npmjs.com/package/@nju33/react-intersection-observed
- Repository: https://github.com/nju33/react-components
- Homepage: https://github.com/nju33/react-components/tree/master/packages/intersection-observed
- npm.io page: https://npm.io/package/@nju33/react-intersection-observed

## Recent versions

- 0.1.31 (latest) — 2018-02-17
- 0.1.30 — 2018-02-17
- 0.1.28 — 2018-02-17
- 0.1.27 — 2018-02-17
- 0.0.3 — 2018-02-17
- 0.0.2 — 2018-02-17
- 0.0.1 — 2018-02-17

## README

# intersection observed

[![@nju33/react-intersection-observed](https://img.shields.io/npm/v/@nju33/react-intersection-observed].svg)](https://www.npmjs.com/package/@nju33/react-intersection-observed])
[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lernajs.io/)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![TypeScript](https://badges.frapsoft.com/typescript/code/typescript.svg?v=101)](https://github.com/ellerbrock/typescript-badges/)

## Install

```bash
yarn add @nju33/react-intersection-observed
```

```bash
yarn add react react-dom @types/react @types/react-dom
```

## Example

```ts
import intersectionObservedFactory = require('@nju33/react-intersection-observed');
import {
  IntersectionObservedProps,
  IntersectionObservedComponent,
  IntersectionObserved
} from '@nju33/react-intersection-observed';

interface FooProps {
  foo: string;
}

type FooIntersectionProps = FooProps & IntersectionObservedProps

class Foo extends React.Component<FooIntersectionProps>
  implements IntersectionObservedComponent {
  render() {
    return <div ... />;
  }

  // optional
  componentOnEnter() {
    console.log('componentOnEnter');
  }

  // optional
  componentOnceEnter() {
    console.log('componentOnceEnter');
  }

  // optional
  componentOnLeave() {
    console.log('componentOnLeave');
  }

  // optional
  componentOnceLeave() {
    console.log('componentOnceLeave');
  }

  componentWillUnmount() {
    this.props.intersectionObserved.unobserve();
  }
}

const intersectionObserved = intersectionObservedFactory();
const IntersectionObservedFoo = (intersectionObserved as IntersectionObserved<FooProps>)(Foo);

<IntersectionObservedFoo foo="foooo" />
```

## With the StyledComponents

If you have used styled-components, you've to apply `intersectionObserved`earlier than `styled`.

e.g.

```ts
const IntersectionObservedFoo = (intersectionObserved as IntersectionObserved<
  FooProps
>)(Foo);
const styledFoo = styled(IntersectionObservedFoo);

<styledFoo foo="fooooo" />;
```

## Customize

you can adjust determine when an element entered into the view.
For that you've to set the `isEnter` function in the argument object of the `intersectionObservedFactory`.

```ts
// intersectionObservedFactory({
//   isEnter(entry: IntersectionObserverEntry): boolean;
// })
intersectionObservedFactory({
  isEnter(entry: IntersectionObserverEntry) => entry.intersectionRatio !== 0;
})
```

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