react-rawb-intersection-observer

1.0.1 • Public • Published

React RAWB Intersection Obeserver

If you want to have component react when they are in the viewport, this simple component helps you just do that.

How to use

import React from 'react';
import IntersectionObserver from 'react-rawb-intersection-observer';

class SuperCoolComponent extends React.Component {

    constructor (props, context) {
        super(props, context);
        this.state = {
            visible: false,
        };
    }

    visible () {
        this.setState({visible: true});
    }

    render () {
        return (
            <IntersectionObserver onVisible={this.visible.bind(this)} threshold={.5}>
                    { this.state.visible }
            </IntersectionObserver>
        );
    }

}

By wrapping you component with IntersectionObserver and giving a treshhold value (how much should be visible in the viewport in %), it will call the onVisible callback.

As simple as that.

Readme

Keywords

none

Package Sidebar

Install

npm i react-rawb-intersection-observer

Weekly Downloads

3

Version

1.0.1

License

MIT

Unpacked Size

13.3 kB

Total Files

6

Last publish

Collaborators

  • camilo.tapia