I am building a simple counter application that can increase or decrease the "streak" number (total number). The increase/ decrease buttons work however, I am having difficulty implementing if/else logic. As you can see in the code I am trying to return a message "CongratsGreeting" whenever the "streak" counter reaches a value of 10.
function CongratsGreeting(props) {
return <h1>Congrats on reaching 10!</h1>;
}
const CounterScreen = () => {
const [counter, setCounter] = useState(0);
return <View style={styles.container}>
<Button title="Increase" color='#0d97a6' onPress={() => {
setCounter(counter + 1);
if (counter == 10) {
return <CongratsGreeting />;
}
}} />
<Button title="Decrease" color='#0d97a6' onPress={() => {
setCounter(counter - 1);
}} />
<Text style={styles.streak}>Streak: {counter}</Text>
</View>
};
CongratsGreetinga separate component?