Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-intersection-observer

Package Overview
Dependencies
Maintainers
1
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-intersection-observer - npm Package Compare versions

Comparing version 4.0.1 to 4.0.2

2

package.json
{
"name": "react-intersection-observer",
"version": "4.0.1",
"version": "4.0.2",
"description": "Monitor if a component is inside the viewport, using IntersectionObserver API",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -12,26 +12,4 @@ # react-intersection-observer

```js
import Observer from 'react-intersection-observer'
> **Storybook demo:** https://thebuilder.github.io/react-intersection-observer/
const Component = () => (
<Observer>
{inView => <h2>{`Header inside viewport ${inView}.`}</h2>}
</Observer>
)
export default Component
```
## Demo
See https://thebuilder.github.io/react-intersection-observer/ for a demo.
#### Scroll monitor
This module is used in
[react-scroll-percentage](https://github.com/thebuilder/react-scroll-percentage)
to monitor the scroll position of elements in view. This module is also a great
example of using `react-intersection-observer` as the basis for more complex
needs.
## Installation

@@ -51,18 +29,2 @@

## Props
The **`<Observer />`** accepts the following props:
| Name | Type | Default | Required | Description |
| --------------- | ----------------------- | ------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **children** | Func/Node | | false | Children should be either a function or a node |
| **render** | ({inView, ref}) => Node | | false | Render prop allowing you to control the view. |
| **root** | HTMLElement | | false | The HTMLElement that is used as the viewport for checking visibility of the target. Defaults to the browser viewport if not specified or if null. |
| **rootId** | String | | false | Unique identifier for the root element - This is used to identify the IntersectionObserver instance, so it can be reused. If you defined a root element, without adding an id, it will create a new instance for all components. |
| **rootMargin** | String | '0px' | false | Margin around the root. Can have values similar to the CSS margin property, e.g. "10px 20px 30px 40px" (top, right, bottom, left). |
| **tag** | String | 'div' | false | Element tag to use for the wrapping element when rendering using 'children'. Defaults to 'div' |
| **threshold** | Number | 0 | false | Number between 0 and 1 indicating the the percentage that should be visible before triggering. Can also be an array of numbers, to create multiple trigger points. |
| **triggerOnce** | Bool | false | false | Only trigger this method once |
| **onChange** | Func | | false | Call this function whenever the in view state changes |
## Usage

@@ -126,4 +88,29 @@

### Polyfill for intersection-observer
## Props
The **`<Observer />`** accepts the following props:
| Name | Type | Default | Required | Description |
| --------------- | ----------------------- | ------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **children** | Func/Node | | false | Children should be either a function or a node |
| **render** | ({inView, ref}) => Node | | false | Render prop allowing you to control the view. |
| **root** | HTMLElement | | false | The HTMLElement that is used as the viewport for checking visibility of the target. Defaults to the browser viewport if not specified or if null. |
| **rootId** | String | | false | Unique identifier for the root element - This is used to identify the IntersectionObserver instance, so it can be reused. If you defined a root element, without adding an id, it will create a new instance for all components. |
| **rootMargin** | String | '0px' | false | Margin around the root. Can have values similar to the CSS margin property, e.g. "10px 20px 30px 40px" (top, right, bottom, left). |
| **tag** | String | 'div' | false | Element tag to use for the wrapping element when rendering using 'children'. Defaults to 'div' |
| **threshold** | Number | 0 | false | Number between 0 and 1 indicating the the percentage that should be visible before triggering. Can also be an array of numbers, to create multiple trigger points. |
| **triggerOnce** | Bool | false | false | Only trigger this method once |
| **onChange** | Func | | false | Call this function whenever the in view state changes |
## Scroll monitor
This module is used in
[react-scroll-percentage](https://github.com/thebuilder/react-scroll-percentage)
to monitor the scroll position of elements in view. This module is also a great
example of using `react-intersection-observer` as the basis for more complex
needs.
## Polyfill for intersection-observer
The component requires the [intersection-observer

@@ -130,0 +117,0 @@ API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc