0
votes

Why do I keep getting the error "callback is not a function" in this action in my Vuex store?

updateRemoteUser: ({ state, commit }, callback) => {
  const user = state.user
  axios.put(`/users/${user.id}`, { 
    user: user
  })
    .then(response => {
      commit('changeUser', response.data.user)
      callback(true)
    })
    .catch(errors => {
      console.log(errors)
      callback(false)
    })
},

EDIT And then I'm calling the above action like this:

async setResponses() {
  this.userResponse = await this.updateRemoteUser()
  if(this.userResponse) {
    this.$router.push({ name: 'weddingDetails' })
  }
  else {
    console.log("Something is jacked")
  }
},
2
Can you show us the line of code where you actually call the action updateRemoteUser? - John Smith
@JohnSmith Just updated the question with how I'm using those callbacks.. - ToddT

2 Answers

0
votes

Check if callback is actually being passed to tee action. A simple check would reveal the answer

if (!callback) console.log('tada');
0
votes

When you call the mutation...

this.updateRemoteUser({ 
    callback: (e) => console.log('do something') 
})

On Your Vuex

updateRemoteUser: ({ state, commit }, data) => {
   const user = state.user
   axios.put(`/users/${user.id}`, { 
    user: user
  })
 .then(response => {
    commit('changeUser', response.data.user)
     if (data.callback) data.callback(true)
  })
  .catch(errors => {
    console.log(errors)
    if (data.callback) data.callback(false)
  })
},