javascript - Await keyword not working within Redux action -


i'm trying incorporate async/await syntax redux actions but, reason, it's not working. cannot life of me see wrong following:

const actions = {     load: async (staff, date) => dispatch => {         const data = {             datefrom: date,             dateto: date,             person: staff,             persontype: 'staff'         };          const events = utils.getdatapromise('json/events/load', data);         const classes = utils.getdatapromise('json/timetable/load', data);          dispatch({             type: actions.myday_load,             staff,             date: date || new date(),             events: await events,             classes: await classes         });     }, } 

the utils function returns promise.

this common mistake due arrow functions syntax.

your load function async returns anonymous arrow function dispatch => {...}.

await works when it's inside async function , await calls inside anonymous returned function not async that's why doesn't work. move async before dispatch , should work.

const actions = {     load: (staff, date) => async dispatch => {...}     //                     ^^^^^ move here ... } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -