React native React本机异步存储无法获取数据

React native React本机异步存储无法获取数据,react-native,asyncstorage,React Native,Asyncstorage,我正在用npm start启动我的react原生项目。在我的模拟器上,我安装了expo来查看我的应用程序。我还使用谷歌浏览器调试我的应用程序 我不知道我做错了什么,但我无法从异步存储中获取任何数据。你能给我一些如何纠正这个问题的建议吗 在我的一项活动中,我使用存储数据 storeDataInAsync1(idSchool,year) { try { //await AsyncStorage.removeItem('user'); A

我正在用npm start启动我的react原生项目。在我的模拟器上,我安装了expo来查看我的应用程序。我还使用谷歌浏览器调试我的应用程序

我不知道我做错了什么,但我无法从异步存储中获取任何数据。你能给我一些如何纠正这个问题的建议吗

在我的一项活动中,我使用存储数据

 storeDataInAsync1(idSchool,year) {
      try {
            //await AsyncStorage.removeItem('user');

            AsyncStorage.setItem('dateRange', this.props.range);
            AsyncStorage.setItem('idSchool', idSchool);
            AsyncStorage.setItem('school_year', year);

          } catch (error) {
            // Error saving data
          }
    }
我对这种方法的呼吁

async saveMyProfil() {
    var formData  = new FormData();
    formData.append('id_school',this.props.idSchool);
    formData.append('school_year', this.props.year);





    await fetch(`${api.url}/my_profile/`, {
        method: 'POST',
        headers: {
          "Content-Type": "multipart/form-data"
        },
        body: formData,
      }).then((response) => response.json())
        .then((json) => {
          console.log('Response: ' + JSON.stringify(json));
          this.storeDataInAsync1(json.id_school,json.school_year);

          //_storeData(json.id_school,json.school_year);
          //this.doStuff(json.id_school,json.school_year);
        })
        .catch((error) => {

        });
  }

  back() {
    //this.storeDataInAsync();
    this.saveMyProfil();
    this.props.navigation.goBack();
  }
在另一个活动中,有一种检索数据的方法

_retrieveData = async () => {
      try {
        const value = await AsyncStorage.getItem('idSchool');
        const year = await AsyncStorage.getItem('school_year');



        if (value !== null && year !== null) {
          // We have data!!
          console.log('Id School: ' + value);
          console.log('Year: ' + year);
        }
       } catch (error) {
         // Error retrieving data
       }
    }
我把它叫进来

componentDidMount() {
        BackHandler.addEventListener('hardwareBackPress', this.handleBackButton);

        this._retrieveData();




    }

只能以字符串格式将数据存储在
AsyncStorage
中。尝试放置断点并检查值是否实际存储。此外,您不能将
wait
.then()一起使用。只需使用
fetch().then().catch()
并删除
async wait
。如何放置断点??我正在开发我的react-in-sublime editor…也可以检查值是否已存储…?你是说你在开发react本机应用程序时没有阅读指南/文档?我已经这样做了:)这是调试的最快方法: