Reputation: 1832
I have following functionality in React Native app
const GreenWood = ({x,y,z,f1,f2, f3}) => {
...
}
I need to convert it to class
class GreenWood extends Component {
constructor(props) {
super(props);
}
...
}
But my props x, y, x are undefined. How to propely forward them?
Upvotes: 2
Views: 4526
Reputation: 4934
I'm guessing you have a functional component GreenWood
that returns some 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
}
}
Upvotes: 5
Reputation: 8936
I don't think you can destructure props on classes. You would have to add this.props in front of all those variables, or inside the method you are using it do:
var { x, y, z, f1, f2, f3 } = this.props
or just put the ones you are using inside that method.
Upvotes: 0