regularly updated local data react

In the I do not want to react to refresh the entire page, just the timing of it refresh the data

Directly on the code

class Refresh extends React.Component {
  static propTypes = {
    classes: PropTypes.object,
  }

  constructor() {
    super();
    this.state = {
      reload: false,   };
  }
  handleResize = () => {
    this.setState({
      reload: true,
    }, () => {
      this.setState({ reload: false });
    });
  }

  componentDidMount() {
    this.resizeHandler = _.debounce(this.handleResize, 500); // 防抖, 当窗口大小改变
    window.addEventListener('resize', this.resizeHandler);
    this.timer = setInterval(() => this.handleResize(), this.state.refreshTimeValue * 1000);
  }
  componentWillUnmount() {
    window.removeEventListener('resize', this.resizeHandler);
    /* eslint-disable */
    this.timer && clearTimeout(this.timer);
     /* eslint-enable */
  }

  render() {
    const { classes } = this.props;
    return (
      <div>
        {this.state.reload ? <div /> :
      (
        <div className={classes.root} id="root">
          <div className="flexBox">
            <div className="item"><AllTimes /></div>
          </div>
        </div>
      )
        }
      </div>
    );
  }
}

export default Refresh;
Published 47 original articles · won praise 42 · Views 140,000 +

Guess you like

Origin blog.csdn.net/zm_miner/article/details/102820629