0
I have a code with 3 Checkbox and when pressed it does not uncheck... Another remark, as I would for when the "UE/HQB" is selected and the others stay disabled={true}
or by first selecting any of the others this "UE/HQB" becomes disabled={true}
I’m using: https://github.com/react-native-community/react-native-checkbox
// Estrutura de CheckBox (isso dentro do state)
checkboxes: [{
id: 1,
title: 'UE/HQB',
checked: false,
}, {
id: 2,
title: 'Exportável',
checked: false,
}, {
id: 3,
title: 'Não exportável',
checked: false,
}],
// Função que lida com o estado dos CheckBox
toggleCheckbox(id) {
const changedCheckbox = this.state.checkboxes.find(cb => cb.id === id);
changedCheckbox.checked = !changedCheckbox.checked;
const checkboxes = Object.assign(
{},
this.state.checkboxes,
changedCheckbox
);
this.setState({ checkboxes });
}
Now the:
// Dentro do return
<CheckBox
key={cb.id}
title={cb.title}
checked={cb.checked}
onPress={() =>
this.toggleCheckbox(
cb.id
)
}
/>
You are using the https://github.com/react-native-community/react-native-checkboxlibrary??
– sant0will
Yes sant0will the one I’m using!
– Victor Hugo Malheiro