Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

149
Views
TypeError: Cannot read properties of null (reading 'find')"

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"
}

enter image description here

7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.