1.0.2 • Published 1 year ago

react-lazy-load-background-image v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

React lazy load background image

Lazy load background image on a react component.

Installation

npm i react-lazy-load-background-image

Usage

import { useLazyBackgroundImage } from 'react-lazy-load-background-image';
import { useRef } from "react";

function SomeBackgroundComponent() {
  const image_url = 'https://picsum.photos/200';
  const elem = useRef(null);
  const imageSource =  useLazyBackgroundImage(elem, image_url);

  return (<div ref={elem} style={{backgroundImage: `url(${imageSource})`}}/>);
}
1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago