Dispatch receiving undefined as a value
I have issue updating the state after a dispatch.
Console logging the result of the dispatch
shows Promise pending
and value undefined
hence, never gets to the store.
console result
Below is the function that calls the dispatch
handler.
unsetSelected()
let some = this.$store.dispatch('user/selectedDevice', null)
console.log(some)
<span class="ellipsis" @click="setSelected(device)">
<i v-if="selectedDevice && selectedDevice.id == device.id"
@click="unsetSelected()"
class="fa fa-times-circle">
</i>
<i v-else="" class="fa fa-ellipsis-v"></i>
</span>
This is the action handler:
selectedDevice ( commit , data)
commit ('SELECTED_DEVICE', data);
vue.js vuex nuxt
add a comment |
I have issue updating the state after a dispatch.
Console logging the result of the dispatch
shows Promise pending
and value undefined
hence, never gets to the store.
console result
Below is the function that calls the dispatch
handler.
unsetSelected()
let some = this.$store.dispatch('user/selectedDevice', null)
console.log(some)
<span class="ellipsis" @click="setSelected(device)">
<i v-if="selectedDevice && selectedDevice.id == device.id"
@click="unsetSelected()"
class="fa fa-times-circle">
</i>
<i v-else="" class="fa fa-ellipsis-v"></i>
</span>
This is the action handler:
selectedDevice ( commit , data)
commit ('SELECTED_DEVICE', data);
vue.js vuex nuxt
add a comment |
I have issue updating the state after a dispatch.
Console logging the result of the dispatch
shows Promise pending
and value undefined
hence, never gets to the store.
console result
Below is the function that calls the dispatch
handler.
unsetSelected()
let some = this.$store.dispatch('user/selectedDevice', null)
console.log(some)
<span class="ellipsis" @click="setSelected(device)">
<i v-if="selectedDevice && selectedDevice.id == device.id"
@click="unsetSelected()"
class="fa fa-times-circle">
</i>
<i v-else="" class="fa fa-ellipsis-v"></i>
</span>
This is the action handler:
selectedDevice ( commit , data)
commit ('SELECTED_DEVICE', data);
vue.js vuex nuxt
I have issue updating the state after a dispatch.
Console logging the result of the dispatch
shows Promise pending
and value undefined
hence, never gets to the store.
console result
Below is the function that calls the dispatch
handler.
unsetSelected()
let some = this.$store.dispatch('user/selectedDevice', null)
console.log(some)
<span class="ellipsis" @click="setSelected(device)">
<i v-if="selectedDevice && selectedDevice.id == device.id"
@click="unsetSelected()"
class="fa fa-times-circle">
</i>
<i v-else="" class="fa fa-ellipsis-v"></i>
</span>
This is the action handler:
selectedDevice ( commit , data)
commit ('SELECTED_DEVICE', data);
vue.js vuex nuxt
vue.js vuex nuxt
asked Nov 14 '18 at 13:56
obi patrickobi patrick
214
214
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I put alert on the mutation handler and discovered that the code was working as expected only that it was also firing the dispatch
function above in the DOM.
I have to chain it with .stop
modifier: @click.stop="unsetSelected()"
add a comment |
From Vuex API reference for dispatch instance methods:
Returns a Promise that resolves all triggered action handlers.
So calling dispatch
returns a Promise. In order to receive data inside component, this promise should be resolved.
You can modify component's method to following:
// using async/await
async unsetSelected()
try
let some = await this.$store.dispatch('user/selectedDevice', null)
console.log(some)
catch (error)
// handle error
// using Promise API
unsetSelected()
this.$store.dispatch('user/selectedDevice', null)
.then((some) =>
console.log(some)
)
.catch((error) =>
// handle error
)
Also, selectedDevice
does not return any data, so some
(or response) from resolved promise will be undefined
for example code provided in question.
To fix that, store action should have a return
statement with desired data to return to the component.
Though, following Vuex architecture, it would be suggested to map state/getters, whose values will be reactively updated after state mutation has been committed.
All you have suggested I have done but still returns undefined. I have getters setup for theselectedDevice
still not working. @aBiscuit
– obi patrick
Nov 14 '18 at 14:21
Were you able to resolve the Promise, but it still showsundefined
? Where do you expect to receive value?
– aBiscuit
Nov 14 '18 at 14:25
I want to receive in the storeexport const state = () =>( devices: null, selectedDevice: null )
Then have it inthe component viacomputed
property
– obi patrick
Nov 14 '18 at 14:52
computed: selectedDevice() return this.$store.getters['user/selectedDevice']
– obi patrick
Nov 14 '18 at 14:54
Please, addSELECTED_DEVICE
mutation code to the question to verify that everything is being updated.
– aBiscuit
Nov 14 '18 at 15:06
|
show 11 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301922%2fdispatch-receiving-undefined-as-a-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I put alert on the mutation handler and discovered that the code was working as expected only that it was also firing the dispatch
function above in the DOM.
I have to chain it with .stop
modifier: @click.stop="unsetSelected()"
add a comment |
I put alert on the mutation handler and discovered that the code was working as expected only that it was also firing the dispatch
function above in the DOM.
I have to chain it with .stop
modifier: @click.stop="unsetSelected()"
add a comment |
I put alert on the mutation handler and discovered that the code was working as expected only that it was also firing the dispatch
function above in the DOM.
I have to chain it with .stop
modifier: @click.stop="unsetSelected()"
I put alert on the mutation handler and discovered that the code was working as expected only that it was also firing the dispatch
function above in the DOM.
I have to chain it with .stop
modifier: @click.stop="unsetSelected()"
answered Nov 15 '18 at 8:37
obi patrickobi patrick
214
214
add a comment |
add a comment |
From Vuex API reference for dispatch instance methods:
Returns a Promise that resolves all triggered action handlers.
So calling dispatch
returns a Promise. In order to receive data inside component, this promise should be resolved.
You can modify component's method to following:
// using async/await
async unsetSelected()
try
let some = await this.$store.dispatch('user/selectedDevice', null)
console.log(some)
catch (error)
// handle error
// using Promise API
unsetSelected()
this.$store.dispatch('user/selectedDevice', null)
.then((some) =>
console.log(some)
)
.catch((error) =>
// handle error
)
Also, selectedDevice
does not return any data, so some
(or response) from resolved promise will be undefined
for example code provided in question.
To fix that, store action should have a return
statement with desired data to return to the component.
Though, following Vuex architecture, it would be suggested to map state/getters, whose values will be reactively updated after state mutation has been committed.
All you have suggested I have done but still returns undefined. I have getters setup for theselectedDevice
still not working. @aBiscuit
– obi patrick
Nov 14 '18 at 14:21
Were you able to resolve the Promise, but it still showsundefined
? Where do you expect to receive value?
– aBiscuit
Nov 14 '18 at 14:25
I want to receive in the storeexport const state = () =>( devices: null, selectedDevice: null )
Then have it inthe component viacomputed
property
– obi patrick
Nov 14 '18 at 14:52
computed: selectedDevice() return this.$store.getters['user/selectedDevice']
– obi patrick
Nov 14 '18 at 14:54
Please, addSELECTED_DEVICE
mutation code to the question to verify that everything is being updated.
– aBiscuit
Nov 14 '18 at 15:06
|
show 11 more comments
From Vuex API reference for dispatch instance methods:
Returns a Promise that resolves all triggered action handlers.
So calling dispatch
returns a Promise. In order to receive data inside component, this promise should be resolved.
You can modify component's method to following:
// using async/await
async unsetSelected()
try
let some = await this.$store.dispatch('user/selectedDevice', null)
console.log(some)
catch (error)
// handle error
// using Promise API
unsetSelected()
this.$store.dispatch('user/selectedDevice', null)
.then((some) =>
console.log(some)
)
.catch((error) =>
// handle error
)
Also, selectedDevice
does not return any data, so some
(or response) from resolved promise will be undefined
for example code provided in question.
To fix that, store action should have a return
statement with desired data to return to the component.
Though, following Vuex architecture, it would be suggested to map state/getters, whose values will be reactively updated after state mutation has been committed.
All you have suggested I have done but still returns undefined. I have getters setup for theselectedDevice
still not working. @aBiscuit
– obi patrick
Nov 14 '18 at 14:21
Were you able to resolve the Promise, but it still showsundefined
? Where do you expect to receive value?
– aBiscuit
Nov 14 '18 at 14:25
I want to receive in the storeexport const state = () =>( devices: null, selectedDevice: null )
Then have it inthe component viacomputed
property
– obi patrick
Nov 14 '18 at 14:52
computed: selectedDevice() return this.$store.getters['user/selectedDevice']
– obi patrick
Nov 14 '18 at 14:54
Please, addSELECTED_DEVICE
mutation code to the question to verify that everything is being updated.
– aBiscuit
Nov 14 '18 at 15:06
|
show 11 more comments
From Vuex API reference for dispatch instance methods:
Returns a Promise that resolves all triggered action handlers.
So calling dispatch
returns a Promise. In order to receive data inside component, this promise should be resolved.
You can modify component's method to following:
// using async/await
async unsetSelected()
try
let some = await this.$store.dispatch('user/selectedDevice', null)
console.log(some)
catch (error)
// handle error
// using Promise API
unsetSelected()
this.$store.dispatch('user/selectedDevice', null)
.then((some) =>
console.log(some)
)
.catch((error) =>
// handle error
)
Also, selectedDevice
does not return any data, so some
(or response) from resolved promise will be undefined
for example code provided in question.
To fix that, store action should have a return
statement with desired data to return to the component.
Though, following Vuex architecture, it would be suggested to map state/getters, whose values will be reactively updated after state mutation has been committed.
From Vuex API reference for dispatch instance methods:
Returns a Promise that resolves all triggered action handlers.
So calling dispatch
returns a Promise. In order to receive data inside component, this promise should be resolved.
You can modify component's method to following:
// using async/await
async unsetSelected()
try
let some = await this.$store.dispatch('user/selectedDevice', null)
console.log(some)
catch (error)
// handle error
// using Promise API
unsetSelected()
this.$store.dispatch('user/selectedDevice', null)
.then((some) =>
console.log(some)
)
.catch((error) =>
// handle error
)
Also, selectedDevice
does not return any data, so some
(or response) from resolved promise will be undefined
for example code provided in question.
To fix that, store action should have a return
statement with desired data to return to the component.
Though, following Vuex architecture, it would be suggested to map state/getters, whose values will be reactively updated after state mutation has been committed.
edited Nov 14 '18 at 14:14
answered Nov 14 '18 at 14:08
aBiscuitaBiscuit
1,4981614
1,4981614
All you have suggested I have done but still returns undefined. I have getters setup for theselectedDevice
still not working. @aBiscuit
– obi patrick
Nov 14 '18 at 14:21
Were you able to resolve the Promise, but it still showsundefined
? Where do you expect to receive value?
– aBiscuit
Nov 14 '18 at 14:25
I want to receive in the storeexport const state = () =>( devices: null, selectedDevice: null )
Then have it inthe component viacomputed
property
– obi patrick
Nov 14 '18 at 14:52
computed: selectedDevice() return this.$store.getters['user/selectedDevice']
– obi patrick
Nov 14 '18 at 14:54
Please, addSELECTED_DEVICE
mutation code to the question to verify that everything is being updated.
– aBiscuit
Nov 14 '18 at 15:06
|
show 11 more comments
All you have suggested I have done but still returns undefined. I have getters setup for theselectedDevice
still not working. @aBiscuit
– obi patrick
Nov 14 '18 at 14:21
Were you able to resolve the Promise, but it still showsundefined
? Where do you expect to receive value?
– aBiscuit
Nov 14 '18 at 14:25
I want to receive in the storeexport const state = () =>( devices: null, selectedDevice: null )
Then have it inthe component viacomputed
property
– obi patrick
Nov 14 '18 at 14:52
computed: selectedDevice() return this.$store.getters['user/selectedDevice']
– obi patrick
Nov 14 '18 at 14:54
Please, addSELECTED_DEVICE
mutation code to the question to verify that everything is being updated.
– aBiscuit
Nov 14 '18 at 15:06
All you have suggested I have done but still returns undefined. I have getters setup for the
selectedDevice
still not working. @aBiscuit– obi patrick
Nov 14 '18 at 14:21
All you have suggested I have done but still returns undefined. I have getters setup for the
selectedDevice
still not working. @aBiscuit– obi patrick
Nov 14 '18 at 14:21
Were you able to resolve the Promise, but it still shows
undefined
? Where do you expect to receive value?– aBiscuit
Nov 14 '18 at 14:25
Were you able to resolve the Promise, but it still shows
undefined
? Where do you expect to receive value?– aBiscuit
Nov 14 '18 at 14:25
I want to receive in the store
export const state = () =>( devices: null, selectedDevice: null )
Then have it inthe component via computed
property– obi patrick
Nov 14 '18 at 14:52
I want to receive in the store
export const state = () =>( devices: null, selectedDevice: null )
Then have it inthe component via computed
property– obi patrick
Nov 14 '18 at 14:52
computed: selectedDevice() return this.$store.getters['user/selectedDevice']
– obi patrick
Nov 14 '18 at 14:54
computed: selectedDevice() return this.$store.getters['user/selectedDevice']
– obi patrick
Nov 14 '18 at 14:54
Please, add
SELECTED_DEVICE
mutation code to the question to verify that everything is being updated.– aBiscuit
Nov 14 '18 at 15:06
Please, add
SELECTED_DEVICE
mutation code to the question to verify that everything is being updated.– aBiscuit
Nov 14 '18 at 15:06
|
show 11 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301922%2fdispatch-receiving-undefined-as-a-value%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown