i在反应本性应用中具有以下操作。我收到错误"调度不是一个函数。我是Redux的新手,并且在异步动作中挣扎。是否可以将异步设置为状态,而无需使用异步/等待?
export const balanceCall =async (dispatch) => {
let token = await getAsyncStoreT();
let mobile= await getAsyncStoreM();
balanceURL = `https://localhost/v1/user/find?token=${token}&mobile=${mobile}`;
console.log(balanceURL);
axios({
method: 'get',
url: checkURL,
}).then(function (response) {
let balance =response.data.map(user=>user.balance);
dispatch(balanceReceived(balance));
})
.catch(function (error) {
console.log(error);
console.log("NOT AGAIN");
});
};
balanceCall
应该返回一个将调度作为参数的函数。相应地更改代码。
export const balanceCall = () => async dispatch => {
let token = await getAsyncStoreT();
let mobile= await getAsyncStoreM();
balanceURL = `https://localhost/v1/user/find?token=${token}&mobile=${mobile}`;
console.log(balanceURL);
axios({
method: 'get',
url: checkURL,
}).then(function (response) {
let balance =response.data.map(user=>user.balance);
dispatch(balanceReceived(balance));
})
.catch(function (error) {
console.log(error);
console.log("NOT AGAIN");
});
};