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-scroll-to-show-cb

v1.2.3

Published

A react component that fires a callback when the wrapped dom scroll into the visible area

Downloads

35

Readme

react-scroll-to-show-cb

React component that fires a callback when the wrapped dom scroll into the visible area

install

npm install react-scroll-to-show-cb --save

usage

support:

  • Before React v16.0
  • After React v16.0
  • preact (preact-compat) - need to set alias: react -> preact-compat , react-dom -> preact-compat

import React from 'react';
import ReactDOM from 'react-dom';
import ReactScrollToShowCb from'react-scroll-to-show-cb';

class App extends React.Component {
    
    render() {
        return <div>
            <ReactScrollToShowCb 
            onScrollToShow={this.handleShow}
            onInitEnd={this.handleInitEnd}
            once={true} 
            wait={500}>
                <div>1</div>
                <div>2</div>
                <div>3</div>
                <div>4</div>
                <div>5</div>
                <div>6</div>
                <div>7</div>
            </ReactScrollToShowCb>
        </div>
    }

    handleShow(index, dom) {
        console.log(`index: ${index}`);
        console.log('dom:', dom);
    }

    handleInitEnd(instance){
        console.log(instance);
    }

}


ReactDOM.render(<App />, document.body);

run the example

npm install --save
npm run dev

The demo app is running at http://localhost:8080.

API

<ReactScrollToShowCb
    onScrollToShow={(index, dom) => {}} 
    onInitEnd={(instance) => {}}
    once={Boolean} 
    async={Boolean}
    wait={Number}> 
    {children}     
</ReactScrollToShowCb>

onScrollToShow

required

When the wrapped children are scrolled into visible view, this callback function will be triggered with two parameters : the index of the child and the dom of the child.

onInitEnd

When ReactScrollToShowCb is initialized, this function will be triggered with a parameter : the instance of ReactScrollToShowCb.

async

default:false

When set to true, you can set the children async and the onScrollToShow will be also triggered.

once

default: true

When set to false, every time the dom showed, the callback will be triggered.

autoInit

default: true

When set to false, you can init ReactScrollToShowCb's instance whenever you want by using ReactScrollToShowCb.Update.

wait

default: 500

The throttle wait time for the callback.

children

required

  • HTML elements, such as div, p, section , are supported.

  • Class react component is supported.

  • Functional react component is not supported.

  • If given an Array, every element of the array should be the same type(the same html element or the same react component);

Static Method

Update

When you change the children, adding a child or removing a child, the ReactScrollToShowCb will not work anymore unless you call the Update method. Usage:

import ReactScrollToShowCb from'react-scroll-to-show-cb';

...
//  ins: the instance of the ReactScrollToShowCb. You can get the instance by [onInitEnd]
ReactScrollToShowCb.Update(ins);
...

Notice that you should call the Update method in the callback of setState. You can find the complete example in the test/index.js.

Note

Do not replace children of react-scroll-to-show-cb. Adding or removing a child is allowed. You can consider using more than one react-scroll-to-show-cb instance if you have children with different child types.