I'm trying to use the panResonder in my React Native app. I tried doing so using class properties instead of constructor and super()
. Here is the code:
export default class Deck extends Component {
panResponder = PanResonder.create({
onStartShouldSetPanResponder: () => true,
onPanResponderMove: (event, gesture) => {},
onPanResponderRelease: () => {}
});
state = { panResponder };
renderCards = () => this.props.data.map(item => this.props.renderCard(item));
render() {
return <View>{this.renderCards()}</View>;
}
}
Unfortunately React is complaining that panResponder is undefined. How is that? Do I have to use a constructor here?
The following code is the only that works for me:
export default class Deck extends Component {
constructor(props) {
super(props);
const panResponder = PanResonder.create({
onStartShouldSetPanResponder: () => true,
onPanResponderMove: (event, gesture) => {},
onPanResponderRelease: () => {}
});
this.state = { panResponder };
}
renderCards = () => this.props.data.map(item => this.props.renderCard(item));
render() {
return <View>{this.renderCards()}</View>;
}
}