The desired behavior is to pass the argument (text) to the onClick handler for console.log, but it seems like I'm doing something wrong with the syntax.
If you leave the argument below, it works fine:
export default class Nav extends Component { componentDidMount() { this.props.pickNumber(3); } onPress() { console.log('FOOOBAAR'); } render() { return ( <View> <Text>####################</Text> <Text>Intro Screen</Text> <Text>Number: {this.props.numbers}</Text> <TouchableHighlight onPress={this.onPress.bind(this)}> <Text>Go to Foo</Text> </TouchableHighlight> </View> ); } }
However, if I want to pass an argument to the onPress handler, it complains: "Cannot read the bind property from undefined.
export default class Nav extends Component { componentDidMount() { this.props.pickNumber(3); } onPress(txt) { console.log(txt); } render() { return ( <View> <Text>####################</Text> <Text>Intro Screen</Text> <Text>Number: {this.props.numbers}</Text> <TouchableHighlight onPress={this.onPress('foo').bind(this)}> <Text>Go to Foo</Text> </TouchableHighlight> </View> ); } }
thanks
Addition: If I change it to:
onPress={this.onPress.bind('foo')}
it doesn't work either.
react-native binding
Wasteland
source share