是否可以在反应渲染函数中返回空? - Is it possible to return empty in react render function?

问题:

I have a notification component, and I have a timeout setting for it.我有一个通知组件,并且有一个超时设置。 After timeout I call this.setState({isTimeout:true}) .超时后我调用this.setState({isTimeout:true})

What I want to do is if already timeout, I want just render nothing:我想要做的是如果已经超时,我只想渲染什么:

render() {
  let finalClasses = "" + (this.state.classes || "");
  if (isTimeout){
    return (); // here has some syntax error
  }
  return (<div>{this.props.children}</div>);
}

The problem is:问题是:

return ();返回 (); // here has some syntax error // 这里有一些语法错误


解决方案:

参考一: https://en.stackoom.com/question/2qZkz
参考二: https://stackoom.com/question/2qZkz
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章