This might be an easy question, but I'm new to React-Native and I'm totally stuck right now.
How do I call function2 from function1?
This is what I've tried, but when pressing the first button it renders an error that says:
Undefined is not a function (evaluating 'this.function2()')
import React, { Component } from 'react';
import {
AppRegistry,
View,
Image,
TouchableOpacity,
} from 'react-native';
export default class Example extends Component {
function1(){
console.log('function1() called');
...
this.function2();
};
function2() {
console.log('function2() called');
...
};
render() {
return (
<View>
<TouchableOpacity onPress={this.function1}>
<Image source={require('../../../assets/img/button.png')} />
</TouchableOpacity>
<TouchableOpacity onPress={this.function2}>
<Image source={require('../../../assets/img/button.png')} />
</TouchableOpacity>
</View>
);
};
}
AppRegistry.registerComponent('Example', () => Example);