The state of my application doesn't change after I press the button specified in the code.
import React from 'react'
import { View, Text, TextInput, Button} from 'react-native'
export default class App extends React.Component {
constructor() {
super()
this.state = {
text: '',
displayText: true
}
}
render() {
return (
<View>
<TextInput
onChangeText={(text) => this.setState({text})}
/>
<Button
onPress={(prevState) => this.setState({displayText: !prevState.displayText})}
title="Display"
/>
{this.state.displayText ? <Text>{this.state.text}</Text> : null}
</View>
)
}
}
If the function passed to onPress is modified so that it changes displayText to false, it works as expected (it hides the text). Most likely the problem is in this portion.
<Button
onPress={(prevState) => this.setState({displayText: !prevState.displayText})}
title="Display"
/>