Hello,
I’m new in app development and also in Expo. So currently I’m trying to develop a simple app where the user will be able to filter some data using checkboxes. For checkboxes I have created two functions and an array, containing the relevant text for each checkbox. So far my code looks like this:
function MyCheckbox() {
const [checked, onChange] = useState(false);
function onCheckmarkPress() {
onChange(!checked);
}
return (
<Pressable
style={[styles.checkboxBase, checked && styles.checkboxChecked]}
onPress={onCheckmarkPress}>
{checked && <Ionicons name="checkmark" size={18} color="white" />}
</Pressable>
);
}
const kategorieList = ["Backware", "Bioprodukte", "Feinkost", "Griechische Spezialitäten", "Molkerei", "Türkische Spezialitäten"]
{kategorieList && kategorieList.map((val, i) => {
return <View style={styles.checkboxContainer}>
<MyCheckbox />
<Text style={styles.checkboxLabel} key={i}>{val}</Text>
</View>
})}
This code work perfectly fine but the following warning ist shown in the console: Warning: Each child in a list should have a unique “key” prop.
Can someone tell me what I’m doing wrong here.
Thank in advance