'What type is this api response?
Im making two seperate api calls to two different endpoints. One returns an array, the other looks like a string, but when i use alert(data) it comes back [object, object] so that should mean its an array correct?
const[searchedResults, setSearchedResults] = useState([]);
const[recipe, setRecipe] = useState([]);
async function searchRecipes(){
const response = await fetch('https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/recipes/complexSearch?query='+searchedRecipe+'&ranking=2', options)
const recipeData = await response.json()
//console.log(recipeData)
setSearchedResults(recipeData.results)
}
async function send(id){
const response = await fetch('https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/recipes/'+id+'/information', options);
const recipeData = await response.json();
alert(recipeData)
setRecipe(recipeData.summary)
console.log(recipeData)
console.log(recipe)
}
search recipes returns an array of objects, the send api call returns this response. I have tried putting it wholesale into state, I have tried recipeData.summary(I removed the summary here to condense the response) to get a specific piece of it , I also have tried parsing the data. No matter what I try I cannot seem to get the any data from this response into state and im lost as to why.
{vegetarian: true, vegan: false, glutenFree: false, dairyFree: false, veryHealthy: true, …}
aggregateLikes: 972
analyzedInstructions: []
cheap: false
cookingMinutes: 5
creditsText: "Deep South Dish"
cuisines: ['American']
dairyFree: false
diets: ['lacto ovo vegetarian']
dishTypes: ['side dish']
extendedIngredients: (6) [{…}, {…}, {…}, {…}, {…}, {…}]
gaps: "no"
glutenFree: false
healthScore: 100
id: 244141
image: "https://spoonacular.com/recipeImages/244141-556x370.jpg"
imageType: "jpg"
instructions: null
lowFodmap: false
occasions: []
originalId: null
preparationMinutes: 10
pricePerServing: 121.4
readyInMinutes: 15
servings: 6
sourceName: "Deep South Dish"
sourceUrl: "http://www.deepsouthdish.com/2009/06/squash-fries.html"
spoonacularScore: 100
sustainable: false
title: "Squash Fries"
vegan: false
vegetarian: true
veryHealthy: true
veryPopular: true
weightWatcherSmartPoints: 3
winePairing: {pairedWines: Array(0), pairingText: '', productMatches: A
this is what I get when I do console.log(recipeData.summary)
You can never have too many side dish recipes, so give Squash Fries a try. This vegetarian recipe serves 6 and costs <b>$1.21 per serving</b>. One portion of this dish contains approximately <b>9g of protein</b>, <b>2g of fat</b>, and a total of <b>325 calories</b>. Plenty of people made this recipe, and 972 would say it hit the spot. From preparation to the plate, this recipe takes around <b>15 minutes</b>. Head to the store and pick up couple turns of the pepper grinder, dash of garlic powder, couple of kosher salt, and a few other things to make it today. This recipe is typical of American cuisine. All things considered, we decided this recipe <b>deserves a spoonacular score of 100%</b>. This score is outstanding. Try <a href="https://spoonacular.com/recipes/delicata-squash-fries-615269">Delicata Squash Fries</a>, <a href="https://spoonacular.com/recipes/cilantro-lime-squash-fries-608435">Cilantro Lime Squash Fries</a>, and <a href="https://spoonacular.com/recipes/baked-butternut-squash-fries-677706">Baked Butternut Squash Fries</a> for similar recipe
this is what I get when I do setRecipe(recipeData.summary) then
console.log(recipe)
[]length: 0[[Prototype]]: Array(0)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
