React native 使用redux thunk和AsyncStorage返回响应
我正在使用react native、redux thunk、jwt和AsyncStorage对该项目中的用户进行身份验证和定位。看起来请求是从axios发送到后端的,但我在chrome控制台中看不到返回的响应(“在axios中”和“?”),我不知道代码中可能出现了什么错误 在我的操作/userAuth.js中React native 使用redux thunk和AsyncStorage返回响应,react-native,jwt,axios,redux-thunk,asyncstorage,React Native,Jwt,Axios,Redux Thunk,Asyncstorage,我正在使用react native、redux thunk、jwt和AsyncStorage对该项目中的用户进行身份验证和定位。看起来请求是从axios发送到后端的,但我在chrome控制台中看不到返回的响应(“在axios中”和“?”),我不知道代码中可能出现了什么错误 在我的操作/userAuth.js中 import { AsyncStorage } from 'react-native'; import axios from 'axios'; export function updat
import { AsyncStorage } from 'react-native';
import axios from 'axios';
export function updateUserLoc(username, lat, lng) {
return function(dispatch) {
AsyncStorage.getItem('token').then(function(token) {
console.log('out');
axios.put(`${ROOT_URL}/:${username}/location`, {location: [lat, lng], token})
.then((response) => {
console.log('in axios');
// console.log('update user location', response);
dispatch({
type: USER_LOC_UPDATE
});
console.log('?');
})
.catch(err => { console.log('user location err', err); });
})
.catch(err => { console.log('Async Storage err', err)});
}
}
以前是否有人遇到过此类问题,或者是否有人知道此代码中存在什么问题以及如何调试它
非常感谢您的建议或回答
谢谢。我认为
AsyncStorage.getItem
不会返回承诺。根据文档,getItem
采用可选的第二个参数,即回调函数。或者,如果您有ES7支持,您可以使用async/await
。我认为AsyncStorage.getItem
不会返回承诺。根据文档,getItem
采用可选的第二个参数,即回调函数。或者,如果您支持ES7,您可以使用async/await