0.0.3 ⢠Published 8 years ago
react-image-render v0.0.3
react-image-render
Load and render an image with react.
Installation
npm install --save react-image-renderUsage
import React from 'react';
import ImageLoader from 'react-image-render';
<ImageLoader src={src}>
{({image, loaded, errored}) => {
if (loaded) {
return (
<img src={src} width={image.width} height={image.height}/>;
}
if (errored) {
return <span>ā</span>;
}
return <span>Loading...</span>;
}}
</ImageLoader>API
Props
src
A string. The image URL.
onLoad
A function called when the image is loaded.
onError
A function called when the image cannot be loaded.
children
The function called to render something when the image is loading, loaded or errored.
Parameters:
status- Anobjectcontaining:loaded- Abooleanindicating whether the image has loaded.errored- Abooleanindicating whether the image has errored.image- TheImageobject which can be inspected to determine thewidthandheightof the image, or drawn onto a canvas withctx.drawImage().
Returns:
A RectNode.