I'm trying implement react-native-elements checkbox. In my case i need to have multiple checkbox based on the array. Below is my code -
const CheckTest = () => {
const [check, setCheck] = useState(false);
const label = [
{
name: 'first'
},
{
name: 'second'
},
{
name: 'third'
},
{
name: 'fourth'
}]
const onValueChange = () => {
setCheck(check => !check)
}
return (
<View style={{ paddingTop: 20 }}>
{label.map(item => {
return <CheckBox
title={item.name}
checked={check}
onPress={(val) => onValueChange(val)}
key={item.name}
/>
})}
</View>
)
}
Problem is in this code is when i select/deselect one checkbox all checkbox are getting checked/unchecked.
I aasume this is happening because of check state as it is applying to all.
How to handle this scnario?
Thanks in advance !!!!!