Recently delving into the world of React, I've been experimenting with state and props. My current goal is to fetch data and use it to populate card views in my application.
Here's a glimpse of what my code looks like at the moment:
class Two extends React.Component {
constructor(props) {
super(props);
this.state = {
day: "Monday",
};
}
// Retrieving monthly schedule
getSchedules = () => {
fetch("http://xxxxxx/getschedules.php", {method: "GET"})
.then((response) => response.json())
.then((responseData) => {
AlertIOS.alert(
"GET Response",
"Search Query -> " + responseData.result.length)
this.setState({day: responseData.result[1].day}); //modifying state but no visible change
})
.then((data) => {
console.log(data);
})
.catch(function(err) {
console.log(err);
})
.done();
}
render() {
<TouchableOpacity onPress={this.getSchedules}>;
<View style={styles.card}>
<Text>{this.state.day}</Text>
</View>
</TouchableOpacity>
}
}
Upon clicking on the card, the text value should update yet remains stagnant. Is there a way for the state to automatically adjust upon page load without requiring interaction from the user? Any assistance would be greatly valued!