I am trying to run the following code block from the official react-native docs:
async function getMoviesFromApi() {
try {
let response = await fetch('https://facebook.github.io/react-native/movies.json');
let responseJson = await response.json();
return responseJson.movies;
} catch(error) {
console.error(error);
}
}
When I try running this I get the error:
"Unexpected token, expected ( (31:17)"
If I remove the function keyword, it works fine.
What difference does it make if I use the function keyword or not? Is it because I am using it in a class? Where in the documentation does it indicate this? Is it in the react-native documentation or the JavaScript documentation? I cannot seem to find it either place, though I could be searching for the wrong thing.
I am using react-native: 0.38.0 (with react-native-cli: 1.2.0)