在React Native中将const转换为class?

sig*_*ami 2 javascript class react-native

我在React Native应用程序中有以下功能

const GreenWood = ({x,y,z,f1,f2, f3}) => {
  ...
}
Run Code Online (Sandbox Code Playgroud)

我需要将它转换为类

class GreenWood extends Component {
  constructor(props) {
      super(props);
  }
  ...
}
Run Code Online (Sandbox Code Playgroud)

但我的道具x,y,x未定义.如何正确地推进他们?

小智 5

我猜你有一个GreenWood返回一些JSX 的功能组件.

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
  }
}
Run Code Online (Sandbox Code Playgroud)