use-intersect
TypeScript icon, indicating that this package has built-in type declarations

0.10.0 • Public • Published

React useIntersect Logo

React useIntersect Hooks

NPM JavaScript Style Guide

Install

npm install --save use-intersect

Usage

import * as React from 'react'
 
import useIntersect from 'use-intersect'
 
const option = {
  threshold: 0.8
}
 
const handleIntersect = (targetElement) ={
  console.log('intersect', targetElement)
}
 
const Example = () => {
 
  const targetRef = useIntersect(handleIntersect, {rootOptions: option, once:true})
 
  return (
    <img ref={targetRef}/>
  )
}

API

useIntersect

Prop Type Required Description
onIntersect Function Execute onItersect Function
IntersectOptions IntersectOptions Intersect option

IntersectOptions type

name Type Required Description
rootOptions ObserverOptions ObserverOptions
once boolean [default:true] Trigger onItersect once

ObserverOptions type

name Type Required Description
root Element | null root Element
rootMargin string Observer rootMargin
threshold number Observer threshold

[MDN]Reference

License

MIT © 🐭snyung

Readme

Keywords

Package Sidebar

Install

npm i use-intersect

Weekly Downloads

224

Version

0.10.0

License

MIT

Unpacked Size

610 kB

Total Files

28

Last publish

Collaborators

  • seonhyung_jo