React的state写在constructor里面和直接写state有什么区别??

 state={
    newAddress: this.props.address,
    }

-------------------------------------------------------------------------------------------------

   constructor(props){
         super(props);
         this.state={
             newAddress: this.props.address,
         }
     }
 

关于上面两种写法,是否结果是第一种newAddress能取到值,而第二种值会是undefined。

阅读 7.1k
2 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题