npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-atom-trigger

v1.0.10

Published

React component to execute code when you scroll to an element. Simple react-waypoint alternative in typescript.

Downloads

162

Readme

react-atom-trigger

Helps solve the problem of executing code when some element "scrolls into (or out of) view". A pretty simple "react-waypoint" alternative written in Typescript.

Basic features

Exposes <AtomTrigger {...props} /> component, where props are:

interface IAtomTriggerProps {
  scrollEvent: ScrollEvent;
  dimensions: Dimensions | null;
  behavior?: 'default' | 'enter' | 'leave';
  callback: () => unknown;
  getDebugInfo?: (data: DebugInfo) => void;
  triggerOnce?: boolean;
  className?: string;
  offset?: [number, number, number, number];
}

In order to "work" AtomTrigger needs callback, dimensions and simple scroll event data provided.

Callback

The function to be executed when AtomTrigger enters or leaves some container.

callback: () => unknown;

Dimensions

Dimensions of the main "container" (window in many cases).

type Dimensions = {
  width: number;
  height: number;
};

So if you have some logic of calculating container size and container resize handling, just provide needed data to AtomTrigger.

Scroll Event

To trigger "events" AtomTrigger needs some kind of simple scroll event provided.

type ScrollEvent = { 
    scrollX: number; 
    scrollY: number;
};

So, if you already have some scroll event listener, just provide it to AtomTrigger.

Utility hooks

For someone who wants everything out-of-the-box, useWindowDimensions, useWindowScroll and useContainerScroll hooks are also available for import.

Examples

It is sometimes better to tweak and see for yourself: CodeSandbox examples.

More detailed react-atom-trigger overview with examples