I'm hazy on async, and I'm not sure why I'm getting a syntax error in my react component while trying to write a simple async method.
class Locations extends React.Component {
constructor(props) {
super(props);
this.searchProducts = this.searchProducts.bind(this);
}
async searchProducts(product_name, storeId) {
let response = await axios.get(
`https://api.goodzer.com/products/v0.1/search_in_store/?storeId=${storeId}&query=${product_name}&apiKey=125cbddf3880cb1ba652a7c269ba1eb0`
);
console.log(response);
return response.data.products;
}
componentWillMount() {
let products = [];
this.props.searchLocations(this.props.navigation.state.params.product_name, this.props.navigation.state.params.searchRadius)
.then(
products = (this.props.locations.map(
location => ({[location.id]: this.searchProducts(
this.props.navigation.state.params.product_name, location.storeid
)}))
)
);
console.log(products);
}
render() {
const displayLocations = this.props.locations.map(
location => (<Text key={location.id}>{location.name}</Text>)
);
return (
<View>
<Text>HELLO</Text>
<View>{displayLocations}</View>
</View>
);
}
}
I'm getting a syntax error: 'Unexpected token, expected ('.
I don't understand how this is any different than the examples given here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/async_function
this.searchProducts()returns aPromiseobject{ "presets": ["babel-preset-expo"], "env": { "development": { "plugins": ["transform-react-jsx-source"] } } }