Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/jopp289/domains/progmans.net/public_html/engine/modules/show.full.php on line 243 react hook api fetch json » Шпаргалки
Заголовок
react hook api fetch json
WEB

import React, { useState, useEffect } from 'react';
import RecipeList from './components/RecipeList

function App() {
  const url = useState(`https://api.myjson.com/bins/t7szj`)
  const [recipes, setRecipes] = useState([])
  const fetchRecipe = async () => {
    const recipeData = await fetch(url)
    const { recipes } = await recipeData.json()
    setRecipes(recipes)
  }

  useEffect(() => {
    fetchRecipe()
  })

  return (
    <div className="App">
      <RecipeList recipes={recipes}>
    </div>
  );
}

 

https://medium.com/better-programming/lets-learn-react-hooks-and-context-api-by-building-a-recipe-search-app-63be9d9e1801


Теги: