An open API service indexing awesome lists of open source software.

https://github.com/spoonx/react-preloaded

Show a placeholder while images are being preloaded.
https://github.com/spoonx/react-preloaded

Last synced: about 1 year ago
JSON representation

Show a placeholder while images are being preloaded.

Awesome Lists containing this project

README

          

# React Preload
[![npm version](https://badge.fury.io/js/react-preloaded.svg)](http://badge.fury.io/js/react-preloaded)

A React component to preload images. It renders a passed component during the loader phase, and renders its children once the images have been successfully fetched.

This repository was forked from [Sam Bernard](https://github.com/sambernard/react-preload).

## Installation

### npm

```bash
npm install react-preloaded --save
```

## Usage

```js
var Preload = require('react-preloaded').Preload;
```

```js
var loadingIndicator = (

Loading...
);
var images = [];

{/* content to be rendered once loading is complete*/}

```

## Prop types

```js
propTypes: {
//Rendered on success
children: PropTypes.element.isRequired,

//Rendered during load
loadingIndicator: PropTypes.node,

//Array of image urls to be preloaded
images: PropTypes.array,

//If set, the preloader will automatically show
//the children content after this amount of time
autoResolveDelay: PropTypes.number,

//Error callback. Is passed the error
onError: PropTypes.func,

//Success callback
onSuccess: PropTypes.func,

//Whether or not we should still show the content
//even if there is a preloading error
resolveOnError: PropTypes.bool

//Whether or not we should mount the child content after
//images have finished loading (or after autoResolveDelay)
mountChildren: PropTypes.bool
}
```

## Additional Details

This module also exposes `ImageCache` and `ImageHelper` which can be used to preload images
directly, and can be accessed via `require('react-preloaded').ImageCache` and
`require('react-preloaded').ImageHelper` respectively.

## License

[MIT][mit-license]

[mit-license]: ./LICENSE