Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. import React, { Component } from 'react';
  2.  
  3. import Loading1 from '../images/loading1.gif';
  4.  
  5. class LoadingSpinner extends Component {
  6. constructor(props){
  7. super(props);
  8.  
  9. this.changeState = this.changeState.bind(this);
  10. this.timer = this.timer.bind(this);
  11. }
  12.  
  13. state = {
  14. loadingImg: Loading1,
  15. loading: true
  16. }
  17.  
  18. timer(){
  19. var self = this;
  20. var startTime = new Date().getTime();
  21. var interval = setInterval(function () {
  22. if (new Date().getTime() - startTime > 3000) {
  23. clearInterval(interval);
  24. return;
  25. }
  26. self.changeState();
  27. }, 2000);
  28. }
  29.  
  30. changeState(){
  31. this.setState({
  32. loading: false,
  33. })
  34. }
  35.  
  36. render() {
  37.  
  38.  
  39. const topMargin = {
  40. marginTop: "50px"
  41. }
  42.  
  43.  
  44. return (
  45. <div className="containter" style={topMargin}>
  46. <center>
  47. {this.state.loading ? <img src={this.state.loadingImg} onLoad= {this.timer()} alt="Loading..." /> : <h2>Unable To Find What You Are Looking For!</h2> }
  48. </center>
  49. </div>
  50. );
  51. }
  52. }
  53.  
  54. export default LoadingSpinner;
  55.  
  56. private _isMount = false;
  57.  
  58. componentDidMount() {
  59. this._isMount = true;
  60. }
  61.  
  62. componentWillUnmount()
  63. {
  64. this._isMount = false;
  65. }
  66.  
  67. timerJob()
  68. {
  69. if(this._isMount == false)
  70. return;
  71. // setState
  72. }
  73.  
  74. constructor(props){
  75. super(props);
  76. }
  77.  
  78. componentDidMount() {
  79. this.changeState = this.changeState.bind(this);
  80. this.timer = this.timer.bind(this);
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement