代码之家  ›  专栏  ›  技术社区  ›  Kevin Amiranoff

从React类中的构造函数返回null

  •  0
  • Kevin Amiranoff  · 技术社区  · 6 年前

    我在代码库中看到过:

    Class MyComponent extends React.Component {
    
      constructor(props) {
    
       if(!props.value) return null
    
         this.state = {
    
           value: props.value
    
         }
    
      }
       ....
    
    }
    

    这是一个反应成分。

    我想知道如果你在构造函数中提前返回会发生什么?

    组件会被实例化吗?这会引起问题吗?

    0 回复  |  直到 6 年前