dispatch 不是一个函数,async
dispatch is not a function, async
我在 react-native 应用程序中有以下操作。我收到错误消息“dispatch is not a function。我是 redux 的新手,正在为异步操作而苦苦挣扎。有没有办法在不使用 async/await 的情况下将 Asyncstorage 设置为状态?
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
应该返回一个以 dispatch 作为参数的函数。相应地更改代码。
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");
});
};
我在 react-native 应用程序中有以下操作。我收到错误消息“dispatch is not a function。我是 redux 的新手,正在为异步操作而苦苦挣扎。有没有办法在不使用 async/await 的情况下将 Asyncstorage 设置为状态?
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
应该返回一个以 dispatch 作为参数的函数。相应地更改代码。
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");
});
};