Reputation: 463
I'm using firebase in my app with Vuex. I have this action in vuex
async deleteTodo({ commit }, id) {
await fbs.database().ref(`/todolist/${store.state.auth.userId}/${id}`)
.remove()
.then(() => {
// fix this
console.log('Todo deleted', commit);
})
}
How can I skip {commit}
in params, if I don't need to commit something. I have error like 'commit assigned but never used'
Upvotes: 1
Views: 182
Reputation: 4429
deleteTodo({ commit }, id)
destructures the first parameter. What your action actually receives there is a context
object that has a couple of members. commit
is one of those. By destructuring it like this, you implicitly assign it to a local constant, and then don't use it. Linters don't like that. If you were to replace it with deleteTodo(context, id)
there's a good chance your linter will accept it. If it doesn't, you can also use deleteTodo(_, id)
, though I'd go with the former. (But there's something else you do want to destructure here... read below.)
Although if you're not committing anything as part of these actions, why is this in Vuex? You could simply put it in any stand-alone function. Vuex is specifically for managing state.
Ah, but you do use state! You use store.state.auth.userId
, but you access it from a constant local to your file, presumably the one uses to create the store, instead of the actual state of the store. This will probably work fine in most cases, but it's not the preferred way to do it.
You know where you can also find the state? On that same context object! So best would be to rewrite it like this:
async deleteTodo({ state }, id) {
await fbs.database().ref(`/todolist/${state.auth.userId}/${id}`)
.remove()
.then(() => {
// fix this
console.log('Todo deleted');
});
}
That's the best way to do it.
Upvotes: 2