export class Diet extends Component {
constructor(props) {
super(props);
this.state = {
data: [],
};
}
updateSearch = (e) => {
axios
.get(
`https://api.spoonacular.com/food/products/search?apiKey{1234}&number=100`
)
.then((res) => {
this.setState({ data: res.data });
});
};
render()
return(
<SearchBar
placeholder="Search Food..."
onChangeText={this.updateSearch}
value={data}
/>
<List style={{ paddingTop: hp("2%") }}>
<TouchableOpacity>
{this.state.data.map(({ type }) => (
<Text>{this.state.type.products.title}</Text>
))}
</TouchableOpacity>
</List>
Hey everyone, I'm trying to get data from the Spoonacular database using axios
, I'm trying to search the food with the SearchBar
and display the content in the List, I'm new to programming and I'm not very sure of what I'm doing, when I run the code it tells me [Unhandled promise rejection: Error: Request failed with status code 400]
and nothing shows on the list.
Link to the documentation: https://spoonacular.com/food-api/docs#Search-Grocery-Products