@fenderdigital/react-intersection-observer

0.2.1 • Public • Published

IntersectionObserver for Fender React UI Kit

Description

A custom react hook for the intersection observer.

Installation and Usage

yarn add @fenderdigital/react-intersection-observer --save
import React, { useEffect, useRef } from 'react';
import useIntersectionObserver from '@fenderdigital/react-intersection-observer';

const MyComponent = () => {
  const target = useRef();
  const options = {
    root: null,
    rootMargin: '0px',
    threshold: 0.5,
  };
  const [hasIntersected] = useIntersectionObserver(options, target);
  useEffect(
    () => {
      if (hasIntersected) {
        // do something cool
      }
    },
    [hasIntersected],
  );
  return <img ref={target} src="/foo.jpg" />;
};

Development

Check the Monorepo README for development documentation.

Package Sidebar

Install

npm i @fenderdigital/react-intersection-observer

Weekly Downloads

1

Version

0.2.1

License

UNLICENSED

Unpacked Size

4.38 kB

Total Files

5

Last publish

Collaborators

  • stevenhuynh
  • markv242
  • coopercodecomposer
  • sherbert
  • jcuanan
  • derduher
  • philipyun
  • theloopla
  • jemnon