2017-04-17 28 views
0

我在我的渲染函数中有一个条件。当if语句不符合时,它会在else块显示之前临时显示。React Native条件呈现临时显示内容

render() { 
    let renderedContent = null 

    if (this.props.tabLabel === 'Schedule' && this.getReportsForTab(this.props.reports).length === 0) { 
     renderedContent = (
     <View style={styles.addInspectionContainer}> 
      <Button block primary style={styles.button} onPress={() => this.props.onAddReport()}>Add Inspection</Button> 
     </View> 
    ) 
    } else { 
     renderedContent = (
     <ListView 
      dataSource={this.state.dataSource} 
      renderRow={this.renderReport} 
      renderSectionHeader={this.renderSectionHeader} 
     /> 
    ) 
    } 

    return renderedContent 
    } 

这不应该发生。任何想法如何解决这一问题?

+0

什么是实际问题? – zvona

+0

@zvona当else块被执行时,它不应该显示if块代码。我如何得到它不显示if块代码? –

+0

例如,当this.props.tabLabel ==='completed'时只显示else块。现在,if块在else块显示之前显示几秒钟 –

回答

0

我最终解决了这个问题。当页面未完全加载时,if块显示。我在if语句中添加了一个this.props.loaded:

if (this.props.loaded && this.props.tabLabel === 'Schedule' && this.getReportsForTab(this.props.reports).length === 0) 
相关问题