Lightsyr (Leandro Campos)
Lightsyr (Leandro Campos)
SSolidJS
Created by Lightsyr (Leandro Campos) on 11/12/2024 in #support
Problems to acess objects inside an array
Hey guys, im trying to make a game with solid js using it as my interface library, but im having this weird behavior on createStore signal. I have this store: export const [spaceShip, setSpaceShip] = createStore({ name:"Galahdyx 5C", inventory:{ resources:[] }, currentGasoline:100, maxGasoline:100, shield:10, laser:10, population:6 }) im trying this little thing: When i click on a button, i append an object with this interface on the resources array: { Name: string Quantity: Number } im trying to do that with this function: setSpaceShip("inventory", "resources", resources => { const existingResource = resources.find(resource => resource.name == picketResource); if(existingResource){ return resources.map(resource => { resource.name == picketResource ? {...resource, quantity: (resource.quantity || 0) + 1} : resource }) }else{ return [...resources, { name: picketResource, quantity:1 }] } }); What im doing wrong?
6 replies