I'm trying to push an object to an array using vuex but i'm getting this error. I don't know why in Edge works great, but in Chrome and Opera it doesn't.
TypeError: Cannot read properties of null (reading 'find')"
Vuex store:
export default {
namespaced: true,
state: {
shoppingCartItems: [],
},
mutations: {
SET_ITEM(state, payload) {
if (state.shoppingCartItems.find(item => item.type === 'custom-item')) {
state.shoppingCartItems.push(payload)
} else if (state.shoppingCartItems.find(item => item.name === payload.name)) {
const index = state.shoppingCartItems.findIndex(item => item.name === payload.name)
const value = payload.quantity
state.shoppingCartItems[index].quantity += value
} else {
state.shoppingCartItems.push(payload)
}
},
}
}
In SET_ITEM I'm checking if the payload is an item that already is in the array so instead of adding again, it sums 1 to this specific item. And again, in Edge it's working perfectly, but in Chrome everything seems to be broken.
Example of payload that SET_ITEM is receiving:
payload = {
dimensions: "30x10cm"
extraLine: 2
extraQuote: "no"
frases: [__ob__: Observer]
image: ""
name: "custom-item"
namesQuantity: 1
names: [{…}, __ob__: Observer]
price: 180
quantity: 1
type: "custom-item"
}