In react, I need a bar loading that will appear on the top of the current page until completely render the next requested component. Here is the example what I exactly want, https://www.bd.airtel.com/en
Asked
Active
Viewed 316 times
1 Answers
1
There are quite a bit of libraries available. To match your exact requirement take a look at this react-top-loading-bar
import React, { Component } from 'react';
import LoadingBar from 'react-top-loading-bar';
export default class App extends Component {
state = {
loadingBarProgress: 0
}
add = value => {
this.setState({
loadingBarProgress: this.state.loadingBarProgress + value
})
}
complete = () => {
this.setState({ loadingBarProgress: 100 })
}
onLoaderFinished = () => {
this.setState({ loadingBarProgress: 0 })
}
render() {
return (
<div>
<LoadingBar
progress={this.state.loadingBarProgress}
height={3}
color='red'
onLoaderFinished={() => this.onLoaderFinished()}
/>
<button onClick={() => this.add(10)}>Add 10</button>
<button onClick={() => this.add(30)}>Add 30</button>
<button onClick={() => this.complete()}>Complete</button>
</div>
)
}
}

Vigneshwaran Markandan
- 947
- 1
- 16
- 37
-
1You showed me a bar loading with manual actions. But, I am talking about something automated. Suppose, currently I am on the homepage. When I will click on the link of the about page then it will calculate the rendering time of the about page. Also, loading appears based on that time. – Sonjoy Datta Aug 02 '19 at 12:47
-
2Nothing is automatic, you have to handle your code in such a way you want, you can use life hooks to achieve the same. – Vigneshwaran Markandan Aug 03 '19 at 13:38