简体   繁体   中英

I can not use the data I received while using AsyncStorage

Is there any way to synchronize the data I get with asyncStorage?

I get data in BaseAction.js

import { AsyncStorage } from 'react-native';

async function getData() {
  let auth_token = await AsyncStorage.getItem('auth_token');
  console.log(auth_token);
  return auth_token;
}
export{getData}

I want use this data in here

import {
    request,
    getData,
    api_url
  } from "./BaseAction";


  export function listTask(onComplete) {

    var auth_token = getData();
    console.log(auth_token); ////return[ _40: 0, _65: 0, _55: null, _72: null]

    return request
      .get(api_url)
      .set("Authorization", "Token " + auth_token)
      .end(...
      );
  }
   var auth_token = getData();

你应该这样做在一个async函数,并把await在前面getData (这或许应该被命名为更好的东西,更多的信息)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM