GithubHelp home page GithubHelp logo

mamal72 / react-use-lazy-images Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 2.0 1.84 MB

⚛️ Minimal zero dependency lazy load images solution with a simple React Hook for all images of an element

Home Page: https://codesandbox.io/s/react-use-lazy-images-example-monnz

License: MIT License

TypeScript 100.00%
react reactjs hooks react-hooks lazy-loading lazyload-images

react-use-lazy-images's Introduction

NPM Build Status David npm

react-use-lazy-images

Minimal zero dependency lazy load images solution with a simple React Hook for all images of an element.

Note that this package is using Intersection Observer API and won't do anything if this API isn't available on the user's browser.

Installation

Using NPM:

npm i react-use-lazy-images

Using Yarn:

yarn add react-use-lazy-images

Usage

import React from 'react'
import { useLazyImages } from 'react-use-lazy-images'

const STYLES = {
  height: "5000px",
  margin: '0 auto',
  width: '100%'
}

export function OctoCats() {
  const ref = useLazyImages<HTMLDivElement>({
    placeholderSrc:
      "https://octodex.github.com/images/vinyltocat.png"
  });
  return (
    <div ref={ref} style={STYLES}>
      <h1>React Use Lazy Images</h1>
      <img
        alt="Vinyltocat"
        src="https://octodex.github.com/images/surftocat.png"
      />
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <img
        alt="Surftocat"
        src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png"
      />
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <img
        alt="Justicetocat"
        src="https://octodex.github.com/images/justicetocat.jpg"
      />
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <img
        alt="Private Investocat"
        src="https://octodex.github.com/images/privateinvestocat.jpg"
      />
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <img
        alt="Robotocat"
        src="https://octodex.github.com/images/Robotocat.png"
      />
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <h2>Some Elements Between</h2>
      <img
        alt="Spidertocat"
        src="https://octodex.github.com/images/spidertocat.png"
      />
    </div>
  );
}

Contribution

You can report bugs and issues here.

You can also send a PR if you feel like you can improve or fix something. Don't forget to write/update tests for your changes.

react-use-lazy-images's People

Contributors

mamal72 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

nexushubs mingneo

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.