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-load-lazily

v1.0.1

Published

A tiny library for lazily loading any content in React

Downloads

23

Readme

React-load-lazily is a Tiny library that allows you to load any component or HTML element only when the user scrolls to its position on the viewport.

  • ✅ Uses IntersectionObserver API natively present in the browser.
  • 📦 Lightweight ~ 1.5KB minified & gzipped (7xxKb)
  • 🚀 Easy to use

Installation

npm install react-load-lazily --save
yarn add react-load-lazily

How to use

import LazyLoad from 'react-load-lazily'

Passing component as children

<LazyLoad>
  <MyComponent>
</LazyLoad>

Passing component as props

<LazyLoad component={<MyComponent>}/>

Threshold

Default: 0.1

The threshold property can be used to specify the percentage of the element that must be visible before it is loaded, with the default threshold set at 0.1 (or 10%).

threshold={0.5} Load the component when 50% of it is visible.

threshold={1} Load the component when 100% of it is visible

Note When the height and width properties are not specified, the default is set to none, meaning that the component will be loaded as soon as even one pixel of the element is visible on the viewport.

<LazyLoad threshold={0.5} height="500px" width="100vw">
  <MyComponent>
</LazyLoad>

Choose your own way of styling

<LazyLoad threshold={0.5}  styles={{ height:'100px' , width:'500px' }} className="h-12 w-full" id="myComponent">
  <MyComponent>
</LazyLoad>

Run custom logic

Use onVisible prop to run custom logic when component is visible.

<LazyLoad onVisible={()=> {
   window.alert('visible')
   }}
>
  <MyComponent>
</LazyLoad>

What else

Pass your own props

<LazyLoad onClick={...} onHover={...}>
  <MyComponent>
</LazyLoad>

Author

👤 Hamsaraj

Show your support

Give a ⭐️ if this project helped you!