GithubHelp home page GithubHelp logo

p0o / react-is-scrolling Goto Github PK

View Code? Open in Web Editor NEW
17.0 1.0 9.0 822 KB

Simply detect if users are scrolling in your components in a declarative API

Home Page: https://p0o.github.io/react-is-scrolling/

License: MIT License

JavaScript 100.00%
reactjs scrolling scroll javascript declarative scrollbar

react-is-scrolling's Introduction

Getting started

This package is providing you a Higher Order Component with a declarative API so you can detect if your users are scrolling in the browser or not. Apart from that you can also detect the direction of their scrolling like below.

npm i react-is-scrolling --save

import React, { Component } from 'react';
import IsScrolling from 'react-is-scrolling';

@IsScrolling
export default class YourComponent extends Component {
  render() {
    const { isScrolling, isScrollingDown, isScrollingUp } = this.props;
    
    return (
      <div>
        { isScrolling &&
          <p>You are scrolling</p>
        }
        
        { isScrollingDown &&
          <p>You are scrolling down</p>
        }
        
        { isScrollingUp &&
          <p>You are scrolling up</p>
        }
      </div>
    );
  }
}

Notice that this package is not using an imperative event based system like other packages so it is much more aligned with React's declarative nature. Also it abstracts away all the heavy lifting of debouncing browser's scroll event and is intended to support different browsers.

If you are not using ES7 decorator functions like @IsScrolling or you want to have this package on a stateless/function component, you can simply use it this way:

import React, { Component } from 'react';
import IsScrolling from 'react-is-scrolling';

function YourComponent({isScrolling, isScrollingDown, isScrollingUp}) {
  return (
    <div>
      { isScrolling &&
        <p>You are scrolling</p>
      }

      { isScrollingDown &&
        <p>You are scrolling down</p>
      }

      { isScrollingUp &&
        <p>You are scrolling up</p>
      }
    </div>
  );
}

export default IsScrolling(YourComponent);

Demo

You can check out how it works here

react-is-scrolling's People

Contributors

alex-malyita avatar creativebuilds avatar p0o avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

react-is-scrolling's Issues

No reactive update

If I scroll up and down fast in a fluid motion, it still just says "UP" or "DOWN" and doesn't update until I stop moving. This only detects the initial direction of a series of scroll gestures.

dependencies should be as peer

The react + react-dom will always be used on projects of developers. Requiring them as dependencies may result in unnecessary bundle file size increase in order to include them. Suggest to be peerDependencies instead.

package.json

    "url": "https://github.com/p0o/react-is-scrolling/issues"
  },
  "homepage": "https://github.com/p0o/react-is-scrolling",
- "dependencies": {
+ "peerDependencies": {
    "react": "^15.4.2",
    "react-dom": "^15.4.2"
},

Not support for SSR

My React apps run with Server Side Rendering,,,when use it,,it's make can't access window

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.