Skip to content

This react hook will use an intersection observer to change show state to true when a sentinel element intersects with the viewport.

License

Notifications You must be signed in to change notification settings

dqhendricks/react-show-on-scroll-hook-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

react-show-on-scroll-hook-ts

This react hook will use an intersection observer to change show state to true when a sentinel element intersects with the viewport.

For a working example, view the code sandbox here, or see below.

Example usage:

import React, { useState } from "react";
import { useShowOnScroll } from "./hooks/useShowOnScroll";

const ExampleHookConsumer: React.FC = () => {
  const [show, setShow] = useState(false);
  const sentinelRef = useShowOnScroll(show, setShow);

  return (
    <div>
      {show && (
        <div>
          Hello there!
        </div>
      )}
      <div ref={sentinelRef} />
    </div>
  );
};

export default ExampleHookConsumer;

About

This react hook will use an intersection observer to change show state to true when a sentinel element intersects with the viewport.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published