2.0.0 • Published 3 months ago

use-intersection-hook v2.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

use-intersection-hook

This is a simple React Hooks that trigger a callback all time the element is viewed.

Installation

Just run a yarn add use-intersection-hook or npm i --save use-intersection-hook

How to use

Simply import use-intersection-hook on your component, then call this on that way:

import React, { useEffect } from "react";
import { useIntersectionObserver } from "use-intersection-hook";

export const Example = () => {
  const { observe, disconnect } = useIntersectionObserver();

  useEffect(() => {
    // ... stuff
    return () => disconnect();
  }, []);

  const observerCallback = () => console.log("Hello world was viewed");
  const observerOptions = {
    rootMargin: "20px",
  };

  return (
    <section ref={observe(observerCallback, observerOptions)}>
      <span>Hello world!</span>
    </section>
  );
};

Every time the component was viewed by the client, a callback will be triggered

TODO:

  • Apply some cool CSS to example
  • Deploy example to GH pages!
  • Configure Github Actions
2.0.0

3 months ago

1.4.1

9 months ago

1.4.0

9 months ago

1.3.0

9 months ago

1.2.5

9 months ago

1.2.4

9 months ago

1.2.3

9 months ago

1.2.2

9 months ago

1.2.1

9 months ago

1.2.0

9 months ago

1.1.1

9 months ago

1.1.0

10 months ago

1.0.0

10 months ago