2.0.1 • Published 2 years ago

react-background-image v2.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
2 years ago

react-background-image

Display a placeholder image while the real image loads.

NPM JavaScript Style Guide

Install

npm install --save react-background-image

Usage

import React from 'react';
import BackgroundImage from 'react-background-image';
import placeholder from './images/small.jpg';
import hdImage from './images/large.jpg';

export default function App() {
  return (
    <div className='main'>
      <BackgroundImage
        placeholder={placeholder}
        src={hdImage}
        className='myCustomClass'
        {...otherProps}
      >
        <p className='some-class'>Other element</p>
        <OtherReactComponent />
      </BackgroundImage>
    </div>
  );
}

Props

PropTypeNotes
srcStringHD image to load
placeholderStringPlaceholder image to be immediately displayed
classNameStringOptional custom css class

Demo

https://jonatanramhoj.github.io/react-background-image/

License

MIT © jonatanramhoj