1.0.0 • Published 8 years ago
@matthamlin/re-load v1.0.0
re-load
Re-load is a react component for handling (psuedo-)async loading states.
Example
import Reload from '@matthamlin/re-load'
let src = 'https://my-cool-img-resource.com/img.jpg'
render(
<Reload
propName="src"
src={src}
resolver={() =>
new Promise((resolve, reject) => {
let img = new Image()
img.onload = () => resolve(img)
img.onerror = () => reject('Failed to load the image resource :(')
img.src = src
})
}
>
{({ src, meta }) =>
src === null ? (
<p> Image Loading ... </p>
) : (
<img
src={src}
height={meta.height}
width={meta.width}
alt="My Cool Image"
/>
)
}
</Reload>,
)API
Props
propNameRequired The name of the prop that will be resolvedresolverAn optional function that returns a promise, the value resolved will be set to themetakey in the callback, and the value rejected will be set to theerrorkey in the callbackdelayAn optional delay used ifresolverisn't providedchildrenRequired The callback render function for Reload, it is called with an object containing the following:
{
[this.props.propName]: null | any,
meta?: any,
error?: any
}1.0.0
8 years ago