Greetings, I want you to help me with something that does not work well for me, what happens is that I want to add a data in an array through a function but instead of adding it, it overrides it, I do not know what is wrong, this is my code in redux:
const [lista,setLista]=useState([])
const agregaLista=(id)=>{
setLista([id])
}
What is happening is that by doing
[id]
, you are creating a completely new list, which replaces the old one. If what you want is to add an element to the list, you must store the value of the list in a variable, to which the new element will be added. Once the list has been modified, you do the againset
to save it with the new element.