abdennour / react-progressbar

Basic progress bar in React.js
http://abdennour.github.io/react-progressbar/
MIT License
88 stars 28 forks source link

progressbar during fetching data from backend #10

Closed shangsunset closed 8 years ago

shangsunset commented 8 years ago

Hey,

Can you use this module to show the progress when fetching data from a server? if so, how would you do it? Thanks.

gabemartinez commented 8 years ago

You should be able to pass your data to the component, via ajax.

abdennour commented 8 years ago

@shangsunset , The idea is to manage by state object .. Then you will be able to update the component by calling setState... this is an example (pseudo code) :

componentDidMount() {
   fetchFromServer((donePercentage) => {
     // assuming that donePercentage is a number from 0 to 1. 
       this.setState({completed: donePercentage*100 })
  });
}

render() {

   return (<Progress completed={this.state.completed || 0} />)
}
shangsunset commented 8 years ago

@abdennour thanks for the reply. I guess my question is how to pass donePercentage from backend to front end constantly in the first place. do you keep calling fetchFromServer to get different donePercentage or is there any way better?