繁体   English   中英

createClass到Component类React Conversion

[英]createClass to Component class React Conversion

我有这种格式的代码:

  const Test = React.createClass({
      tabIcons: [],
      propTypes: {
      ...
      },
      render() {
       return
       <View> ...</View>
     }
  })

我不知道如何将tabIcons转换为新格式

class Test extends Component {
 static propTypes = {
  ...
  }
 render () {
  return (
   <View> ...</View>
  )
 }
}

您可以在构造函数中将tabIcons添加为类属性。

class Test extends Component {

 constructor(){
  this.tabIcons = [];
 }

 static propTypes = {
  ...
 }

 render () {
  return (
   <View> ...</View>
  )
 }
}

现在,您可以在类似州的任何地方访问它。

this.tabIcons.push(newItem)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM