2017-05-06 43 views
1

我正在使用react-native,redux-thunk,jwt和AsyncStorage來驗證和定位此項目中的用戶。看起來請求是從axios後端發出的,但我沒有在chrome控制檯中看到迴應('in axios'和'?'未顯示),我不知道我的代碼中可能出現了什麼問題。使用redux-thunk和AsyncStorage獲取響應

在我的行動/ userAuth.js

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)}); 
    } 
} 

有沒有人有這樣的問題之前,或沒有任何人知道問題出在這段代碼是什麼以及如何調試呢?

將欣賞任何形式的建議或答案。

謝謝。

回答

0

我不認爲AsyncStorage.getItem返回一個Promise。根據文檔,getItem採用可選的第二個參數,它是您的回調函數。或者,如果您有ES7支持,則可以使用async/await