0.1.8 • Published 3 years ago

use-on-screen v0.1.8

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Use On Screen

use-on-screen is a React Hooks library used to detect if a certain element is visible on the screen, both in a scrollable container and in the window.

Installation ⚙️

Use the package manager npm to install use-on-screen.

npm install use-on-screen

Usage 🛠️

// ...
import useOnScreen from "use-on-screen";

function FakeFeed() {
    const [visible, position] = useOnScreen({
        target: "#loader", // default: ""
        parent: "#feed", 
        // if the parent is not defined, 
        // it will consider the entire user's viewport
        delay: 500 // default: 1000
    });
    
    // ...
    
    // Use useEffect() to call a function when element is visible
    useEffect(() => {
        if (visible) {
            loadMorePosts();
            console.log(position);
        }
    }, [visible]);

    // ...

    return (
        <section id="feed">
            {/*
                Many other posts over here...
            */}
            <span id="loader"></span> {/* if visible, it will 
            load more posts*/}
        </section>
    );
}

Contributing 💭

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License 📝

MIT

0.1.2

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago