How to use await key word on react native?

后端 未结 4 1407
[愿得一人]
[愿得一人] 2020-12-09 07:28

I tried to use await/async on react native,but I got unexpected token error.

I added the code blow in my javascript source file:

var value = await As         


        
4条回答
  •  青春惊慌失措
    2020-12-09 07:57

    I'm using async/await in my react native app and didn't have to do anything to configure or enable it in my project. My usage takes the form of...

    async getCache(key){
        try{
            let value = await AsyncStorage.getItem(key);
            return value.json();
        }
        catch(e){
            console.log('caught error', e);
            // Handle exceptions
        }
    
    }
    

    Note: If you use an await inside a function that is not explicitly declared with async, you'll end up with an Unexpected token syntax error.

提交回复
热议问题