-1

How to get number '1' of this TouchableOpacity?

numClick(){
    this.state.pressedNum = ?
}
render(){
    return (
        <TouchableOpacity style={styles.numButton} onPress={()=>this.numClick()}>
            <Text style={styles.numString}>1</Text>
        </TouchableOpacity>
}
Jeaf Gilbert
  • 11,495
  • 19
  • 78
  • 105

1 Answers1

1

Do you need to extract the value from the actual Text component? If not you can just pass it to the function as an argument. By the way, you should not mutate state directly, use setState() instead.

numClick(num) {
    this.setState({
        pressedNum: num
    });
}

render() {
    return (
        <TouchableOpacity style={styles.numButton} onPress={()=>this.numClick(1)}>
            <Text style={styles.numString}>1</Text>
        </TouchableOpacity>
    )
}
MC10
  • 552
  • 1
  • 12
  • 26