I'm having problems with the onPress function. OnPress should only work when it was actually triggered by a touch event (I suppose), that is, when I click a button on the screen. But it seems that onPress launches itself when the render function is called. When I try to click manually, this will not work.
import React, { Component } from 'react'; import { PropTypes, Text, View ,Alert } from 'react-native'; import { Button } from 'react-native-material-design'; export default class Home extends Component { render() { return ( <View style={{flex:1}}> <Button value="Contacts" raised={true} onPress={this.handleRoute('x')} /> <Button value="Contacts" raised={true} onPress={this.handleRoute('y')} /> <Button value="Contacts" raised={true} onPress={this.handleRoute('z')} /> </View> ); } handleRoute(route){ alert(route)
What am I missing? Is there something wrong with the way I assigned, or is this some kind of mistake? Any suggestion is much appreciated.
Video
source share