Uncaught TypeError: Cannot match against 'undefined' or 'null'.
See original GitHub issueHi,
I try to create an API module which will be used by other modules in my store to ask for data then apply my business logic on top of it.
Here is my api.js
file:
import Vue from 'vue'
import { createStore, Resource } from 'vuex-rest-api'
const options = {
axios: Vue.axios
}
const resource = new Resource(__API_ROOT__, options)
// Auth (User and Guest cases)
resource
.addAction({
action: "login",
method: "post",
property: "token",
pathFn: () => '/auth/login'
})
.addAction({
action: "getGuestHash",
method: "get",
property: "guest_hash",
pathFn: () => '/auth/get_guest_hash'
})
// Cart
.addAction({
action: "getCart",
method: "get",
property: "cart",
pathFn: (id) => `/carts/${id}`
})
.addAction({
action: "createCart",
method: "post",
property: "cart",
pathFn: () => `/carts`
})
.addAction({
action: "cleanCart",
method: "put",
property: "cart",
pathFn: () => `/carts/clean`
})
.addAction({
action: "getActiveCart",
method: "get",
property: "activeCart",
pathFn: () => `/carts/active`
})
.addAction({
action: "changeDomiciliationOffer",
method: "put",
property: "cart",
pathFn: (id) => `/carts/${id}`
})
.addAction({
action: "addOffer",
property: "cart",
})
export default createStore(resource)
my store/index.js
file:
import Vue from 'vue'
import Vuex from 'vuex'
import mutations from './mutations'
import actions from './actions'
import getters from './getters'
import api from './modules/api'
Vue.use(Vuex)
const state = {
count: 0
}
const store = new Vuex.Store({
state,
mutations,
actions,
getters,
modules: {
api
}
})
export default store
Here is the error I get from the console:
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
TypeError: Cannot match against 'undefined' or 'null'
this error should only arise if the array or object being destructured or its children is undefined or null . Exactly. In your...
Read more >Uncaught TypeError: Cannot match against 'undefined' or 'null'.
At C:\Users\morta\AppData\Local\atom\app-1.23.3\resources\app\src\tokenized-buffer.js:517 TypeError: Cannot match against 'undefined' or 'null'. at ...
Read more >Getting to Grips with ES6: Destructuring - Medium
ES6 destructuring allows us to achieve the same result with a much more concise syntax. ... Uncaught TypeError: Cannot match against 'undefined' or...
Read more >Uncaught TypeError: Cannot match against 'undefined' or 'null'.
Uncaught TypeError : Cannot match against 'undefined' or 'null'.
Read more >Cannot destructure Property of Undefined Error in JS
The "Cannot destructure property of undefined" error occurs when we try to destructure a property from a value that is equal to `undefined`....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@sotaan I just saw another error in your code snippet. You have to destructure the params in the path fn. False:
Correct:
I just found that I needed to call my actions that way:
this.store.$dispatch('myaction', {})
to get it working. Calling that way:this.store.$dispatch('myaction')
will trigger the error. I suggest that it must come from destructing assignment in your params in here: storeCreator.tstry that:
storeActions[dispatchString] = async ({ commit }, { params = {}, data = {} } = {}: ActionParamsBody) => { ...