I simply made a state object since there was no need of constructor. I accessed props in that state object as this.props
, so here in this state object I am able to access the props using this
keyword. Can someone state any reason for not using it the current way and defining a constructor. state={visibility: this.props.visibility}
got following result from babel.repl
我找到了答案,如果我们在构造函数中或在类https://michalzalecki.com/react-components-and-class-properties/中进行初始化,则没有任何区别
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.