1.0.7 • Published 5 years ago

react-on-intersect v1.0.7

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

react-on-intersect

npm version stability-unstable Build Status dependency status js-standard-style

React hook to do something when two elements intersect.

Hooks are an upcoming feature that lets you use state and other React features without writing a class. They’re currently in React v16.7.0-alpha.

Demo

Infinite Scroll

Installation

npm install react-on-intersect

Usage

import React, { useRef } from 'react'
import useIntersect from 'react-on-intersect'

export default function Example () {
  const element = useRef(null)

  function onEnter () {
    console.log('Hi!')
  }

  function onExit () {
    console.log('Bye!')
  }

  useIntersect({ onEnter, onExit, element })

  return (
    <>
      <h1
        ref={element}
        style={{ marginTop: '110vh', textAlign: 'center', fontSize: '4em' }}
      >
        Hello, Intersect!
      </h1>
    </>
  )
}

API

useIntersect({ onEnter, onExit, element, options })

onEnter(entry)

A function which is called when elements start intersecting.

onExit(entry)

A function which is called when elements stop intersecting.

element

Target element to watch.

options

See Intersection Observer#Parameters for available options.

Prior art

on-intersect

Read more

Intersection Observer API

License

MIT

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago