export class Diet extends Component {
constructor(props) {
super(props);
this.state = {
data: [],
searchValue: "",
};
}
updateSearch = (value) => {
this.setState({ searchValue: value });
if (value.trim() !== "") {
axios
.get(
`https://api.edamam.com/api/food-database/v2/parser?ingr=${value}&app_id=2626c70d&app_key=0c0f87ae4e5437621363ecf8e7ea80ae`
)
.then((res) => {
this.setState({ data: console.log(res.data.hints) });
})
.catch((error) => {
console.log(error.response.data);
});
}
};
return (
<SearchBar
placeholder="Search Food..."
onChangeText={this.updateSearch}
value={searchValue}
/>
<FlatList
style={{ paddingTop: hp("2%") }}
data={this.state.data.map((item) => item.food)}
renderItem={({ item }) => (
<List>
<ListItem>
<Left>
<TouchableOpacity>
<Text>{item.label}</Text>
</TouchableOpacity>
</Left>
<Right>
<Icon
name="arrow-forward"
style={{ fontSize: 25, color: "red" }}
/>
</Right>
</ListItem>
</List>
)}
keyExtractor={(item) => item.foodId}
/>
Hi everyone, I'm trying to get data from the API of Edamam, I'm using a SearchBar
to get the value the user is typing and show the list of the label
of foods in the FlatList
below, the URL works fine, when I run the code and I start typing the console.log
returns 'undefined'.
Link to documentation: https://developer.edamam.com/food-database-api-docs