I am a student trying to learn react-native for school. I've encountered this error. Any idea how to fix this error?
'Too many re-renders. React limits the number of renders to prevent an infinite loop'.
My code:
import React, {useState} from 'react';
import Icon from 'react-native-vector-icons/dist/MaterialIcons';
import {
SafeAreaView,
StatusBar,
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native';
const App = () => {
let [count, setCount] = useState(0);
setCount(0);
function onPressIncrease() {
count++
}
function onPressDecrease() {
count--
}
return (
<SafeAreaView style={styles.container}>
<StatusBar />
<View style={styles.container}>
<Text style={styles.titleText}>{count}</Text>
<View
style={{
flexDirection: 'row',
}}>
<TouchableOpacity onPress={onPressIncrease}>
<View>
<Icon name="add" size={24} color="black" />
</View>
</TouchableOpacity>
<View style={styles.emptySpace} />
<TouchableOpacity onPress={onPressIncrease}>
<View>
<Icon name="remove" size={24} color="black" />
</View>
</TouchableOpacity>
</View>
<StatusBar />
</View>
</SafeAreaView>
);
};
export default App;
All help is very much appreciated!