How do I stop a component rendering before data is fetched?

前端 未结 3 2000
后悔当初
后悔当初 2021-02-04 17:03

Currently in react I have to functions in the componentDidMount lifecycle method in which call action creators to which fetch data. The component uses the data however, dependin

3条回答
  •  悲哀的现实
    2021-02-04 17:55

    You can't stop the render but you can give conditions to what to render.

    Example

    render() {
        if(this.props.hours. length <= 0 || this.props.trained.length <= 0 ) {
          return (
    Loading...
    ); } else { let hours = parseInt(_.map(this.props.hours, 'hours')); let trained = _.map(this.props.trained, 'trained'); return (
    ) }

提交回复
热议问题