My app has a component that consists of three buttons(only two are relevant though.) Yesterday I discovered that my setanimalNumber(animalNumber + 1) has stopped working. Animal number no longer increments.
const AnimalButton = ({remove, animalz, addtoList}) => {
const [animalNumber, setanimalNumber] = useState(1)
return (
<View style={styles.buttonGrouptrue} >
<Button title={animalNumber + ' ' + animalz}
onPress={() => remove(animalz)}
buttonStyle={styles.button} titleStyle={{color: 'black'}}
/>
<View style={styles.directionalButtons}>
<TouchableOpacity
onPress={() => {
setanimalNumber(animalNumber, animalNumber + 1)
addtoList([animalz, animalNumber + 1])
}}
style={styles.arrowButton}
>
<Image
style={{
marginLeft: 'auto',
marginRight: 'auto'
}}
source={require('../assets/arrow_up.png')}
></Image>
</TouchableOpacity>
</View>
</View>
);
}
I have looked around throughout stack overflow and I have tried the following options.
setanimalNumber(animalNumber => animalNumber + 1)
setanimalNumber(animalNumber++)
setanimalNumber(animalnNumber, animalNumber + 1)
const test = (value) => {
let newValue = value + 1
setanimalNumber(newValue)
}
I know this is a common issue, but none of the solutions I found seemed to work. Any advice at all would be appreciated.