[英]Convert const to class in React Native?
我在React Native应用程序中具有以下功能
const GreenWood = ({x,y,z,f1,f2, f3}) => {
...
}
我需要将其转换为类
class GreenWood extends Component {
constructor(props) {
super(props);
}
...
}
但是我的道具x,y,x是不确定的。 如何正确转发它们?
我猜您有一个返回某些JSX的功能组件GreenWood
。
class Greenwood extends React.Component {
constructor(props) {
super(props)
//...whatever construction you need
}
render() {
const { x, y, z, f1, f2, f3 } = this.props
return // your JSX Here
}
}
我认为您无法破坏课堂上的道具。 您将必须在所有这些变量前面或您正在使用的方法内部添加this.props:
var { x, y, z, f1, f2, f3 } = this.props
或者只是将您要使用的内容放在该方法中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.