-
-
Save olajohn-ajiboye/55a7ed037f0113e7475a95b771553222 to your computer and use it in GitHub Desktop.
UseEffect experiment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from 'react'; | |
import RecipeList from './components/RecipeList' | |
import RecipeDetails from './components/RecipeDetails' | |
function App() { | |
const apiKey = `36920f6651c9cd9d91a6c3205cabaa19` | |
let url = `https://www.food2fork.com/api/search?key=${apiKey}` | |
const [showHomeButton, setShowHomeButton] = useState(false) | |
const [recipes, setRecipes] = useState([]) | |
const [loading, setLoading] = useState(true) | |
const [search, setSearch] = useState('') | |
const fetchRecipe = async () => { | |
const recipeData = await fetch(url) | |
const { recipes } = await recipeData.json() | |
setRecipes(recipes) | |
setLoading(false) | |
console.log("I am beign rendered again and again") | |
} | |
useEffect(() => { | |
fetchRecipe() | |
}) | |
return ( | |
<div> | |
{loading ? <h1 className="text-center">…fetching {search} Recipe</h1> : | |
<RecipeList recipes={recipes} />} | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment