2
I am trying to store the ID of some accounts that have been selected by a checkbox, that is I will have an array of all accounts that are selected, but I need that when it is unchecked, delete their id from the array, i tried to make a filter with map in the array but nothing returned me, nor the console log I put to test.
const [contasSelected, setSelected] = useState([])
function cSelect(e) {
contasSelected.map(a => {
if (a.ID = e) {
console.log('o ID', a.ID, 'já está marcado')
} else {
setSelected([...contasSelected, {
ID: e
}])
console.log(contasSelected)
}
})
}
<tbody className='Table-Contas-Body'>
{Contas.map( e =>(
<tr key={ e.ID}>
<FormCheck id={ e.ID} type="checkbox" onChange={ ()=> cSelect(e.ID)}/> // aqui é onde passo o ID da conta para a função
<td>{e.ID}</td>
<td>{e.Cliente}</td>
<td>{e.Valor}</td>
<td>{e.DataEmissao}</td>
<td>{e.DataVencimento}</td>
<td>{e.Historico}</td>
</tr>
))}
</tbody>
Thanks for the help, I will scan my code again and do with findindex.
– Matheus Martins