Giter Club home page Giter Club logo

react-images-preload's Introduction

React Images preload promise Build Status npm version

This libray help you deal with all messy preloading image in your react component

Feature

Resolve all giving imageURLs and then tell composite component when everything done

  • use as Higher order component
  • use as Component (Soon)

Installation

NPM

npm install --save react-images-preload

Bower

bower install --save react-images-preload

Usage

With out using module import

<script src="../bower_components/react-images-preload/dist/index.js"></script>

<script>
var Component = React.createClass({....})
var WithimagesLoaded = ImagesLoaded.withImagesPromise({
    image1: 'https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150',
    fox: 'http://coolwildlife.com/wp-content/uploads/galleries/post-3004/Fox%20Picture%20003.jpg'
}, Component);
... render to DOM
</script>

with commonjs module


import * as React from 'react';
import * as ReactDom from 'react-dom';

import * as ImagesPromise from 'react-images-preload';

const mountPoint = document.createElement('div');
mountPoint.id = 'mount';
document.body.appendChild(mountPoint);

const App = ({images, isImagesLoaded}) => (
    <div>
        {
            !isImagesLoaded ? 'Loading...' : 'Done'
        }
        <img src={images['image1']} />
        <img src={images['fox']} />
    </div>
)

const WithimagesLoaded = ImagesPromise.withImagesPromise({
    image1: 'https://placeholdit.imgix.net/~text?txtsize=33&txt=350%C3%97150&w=350&h=150',
    fox: 'http://coolwildlife.com/wp-content/uploads/galleries/post-3004/Fox%20Picture%20003.jpg'
}, App);

ReactDom.render(
    <WithimagesLoaded />,
    document.getElementById('mount')
)

API

ImagesPreload.withImagesPromise

ReactClass withImagesPromise ( imagesURLDatasource: any, component: ReactClass<ImagePromisePropsType> ) 

This function provider higher order component that will receive collection of image url an composite component then do preload state and update composite component props.

Composite component props type

    interface ImagesPromisePropsType {
         // object of imagesURLDataSource. ( will resolve after every images onload)
        images: any 
         // images list preload status.
        isImagesLoaded: boolean 
    }

ImagesPreload.createImageOnLoadPromise

Promise<HTMLImageElement> createImageOnLoadPromise ( url: string, key: string ) 

helper function that create Promise that will resolve Image object after request done.

Development

you can clone this repe and run a few command to run a project

npm install -g gulp mocha
npm install

Build

gulp build

Run

npm start

or just open example/index.html for global module

Testing

npm test

Contribution

Plase feel free to create issues or pull request.

License

MIT

react-images-preload's People

Contributors

zapkub avatar

Stargazers

Kanmanus Ongvisatepaiboon avatar

Watchers

James Cloos avatar  avatar

react-images-preload's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.