1.1.1 • Published 6 years ago

react-image-primitive v1.1.1

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

react-image-primitive Build Status

Declaratively fetch image. Use a render prop to get error/pending/loaded state for the image. Set whether the image can be fetched with prop.

import ImagePrimitive from 'react-image-primitive'
ReactDOM.render(
  <ImagePrimitive
    src={'/my-image.jpg'}
    render={({
      src,
      pending,
      error,
      loaded,
      width,
      height
    }) => !loaded ? <div className='spinner' /> : <img src={src} />}
  />,
  document.body
)

<ImagePrimitive />

Props

src

string

The image src to load.

canLoad

boolean | default true

If canLoad is false and the given src has not been fetched before, it will not be fetched.

onChange

function | optional

Called whenever the loaded state of the image at src changes, with the same props as render (below).

render

function | required

This function is called with ({ src, loaded, pending, error, width, height }) whenever any of those values updates.

Width and height are retrieved from the <img> element used to load the image internally.

Use this to render your elements in reaction to the image loading state (see example at the top).

Also can render with children prop as function.

License

MIT © Andrew Joslin

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago