0.2.0 • Published 6 years ago

react-even-simpler-img v0.2.0

Weekly downloads
7
License
MIT
Repository
github
Last release
6 years ago

React Even Simpler Img

Smaller (< 2KB) alternative of react-simple-img that doesn't include IntersectionObserver polyfill.

Install

npm install --save react-even-simpler-img

Import

import { ImageLoader, SimpleImg } from 'react-even-simpler-img';

Usage

First, wrap your app with :

ReactDOM.render(
  <ImageLoader>
    <App />
  </ImageLoader>,
  rootNode
);

Use as if it's a normal HTML Image element

<SimpleImg src="https://picsum.photos/40" />

Lazy Loading

To lazy load images, set importance prop to low:

<SimpleImg src="https://picsum.photos/40" importance="low" />

This library uses IntersectionObserver to lazy load images. If the browser doesn't support it, this library will gracefully degrade to eager loading approach.

Error Handling

To display a fallback when the image is failed to load, you need to wrap it with an Error Boundary.

// you need to have your own implementation
// of React error boundary
import ErrorBoundary from './MyErrorBoundary';

<ErrorBoundary fallback={<MyImgFallback />}>
  <SimpleImg src="https://rubbish.xyz/foo/bar.jpg" />
</ErrorBoundary>;

Also check out react-error-boundary for ready-made ErrorBoundary component!

0.2.0

6 years ago

0.1.16

6 years ago

0.1.15

6 years ago

0.1.14

6 years ago

0.1.13

6 years ago

0.1.12

6 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.0

6 years ago