Code Monkey home page Code Monkey logo

react-simple-loading-bar's Introduction

react-simple-loading-bar

npm package

Inspired by react-redux-loading-bar but without the middleware. Handles simultaneous active requests.

Demo GIF

Installation

npm install --save react-simple-loading-bar

Including it:

import SimpleLoadingBar from 'react-simple-loading-bar'

<SimpleLoadingBar activeRequests={this.state.activeRequests}></SimpleLoadingBar>

This is my recommended way of using the loading bar (well, not mine, I read it somewhere but I can't remember the source). The important thing is that you need to set activeRequests to a value above 0 when you want to start the loading bar. Set it to 0 when you want the loading bar to finish.

Set these in your state:

activeRequests: state.global.activeRequests

Actions:

const GlobalActions = {

    isLoading: function () {
        return {
            type: 'IS_LOADING'
        }
    },

    hasLoaded: function () {
        return {
            type: 'HAS_LOADED'
        }
    }
}

export default GlobalActions;

Reducer:

const initialState = {
    activeRequests: 0
}

const GlobalReducer = function reducer(state = initialState, action) {
    switch (action.type) {
        case 'IS_LOADING':
            return Object.assign({}, state, { activeRequests: state.activeRequests + 1 });
        case 'HAS_LOADED':
            return Object.assign({}, state, { activeRequests: state.activeRequests - 1 });
        default:
            return state;
    }
};

export default GlobalReducer;

Settings:

Set color:

<SimpleLoadingBar activeRequests={this.state.activeRequests} color={this.state.color}></SimpleLoadingBar>

Set height:

<SimpleLoadingBar activeRequests={this.state.activeRequests} height={this.state.height}></SimpleLoadingBar>

react-simple-loading-bar's People

Contributors

yarism avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-simple-loading-bar'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.