react-progress-bar
Loading bar for your React.js app. Similar to one used in Youtube.

Setup
1. npm install
npm install simple-react-progress-bar
2. In your component.js.jsx
require ('react-progress-bar');
var component = React.createClass({
getInitialState: function() {
return {
startLoading: false,
completeLoading: false
};
},
render: function() {
return (
<div>
<ProgressBar completed={this.state.completeLoading} loading={this.state.startLoading} resetLoading={this.resetLoading} />
{
}
</div>
);
},
startLoading: function(){
this.setState({startLoading: true});
},
endLoading: function(){
this.setState({completeLoading: true});
},
resetLoading: function() {
this.setState({
startLoading: false,
completeLoading: false
});
}
});
3. In your CSS
Add the content of stylesheet.css
to your CSS.
Usage
Call this.startLoading()
to start the loading animation.
Call this.endLoading()
to stop the loading animation.
For example, in an ajax call:
gettingNewStuff: function(){
this.startLoading();
$.ajax({
url: '/get_new_stuff',
type: 'get',
success: function(){
this.endLoading();
},
error: function(){
this.endLoading();
}
})
}