new
App.js
import react, {useEffect, useState}from "react";
import './App.css';
import Header from "./components/Header";
import Recipes from "./components/Recipes";
import Axios from "axios";
function App() {
const [search, setSearch] = useState("Icecream");
const [recipes,setRecipes] = useState([]);
useEffect(()=>{
getRecipe();
},[]);
const getRecipe = async()=>{
const res = await Axios.get(`https://api.edamam.com/search?q=${search}&app_id=${APP_ID}&app_key=${APP_KEY}&from=0&to=3&calories=591-722&health=alcohol-free`)
setRecipes(res.data.hits)
}
const APP_ID = "09fd6cf9";
const APP_KEY = "5645169c14b6b1216a543e0cfbd04e37";
const onInputChange = e =>{
setSearch(e.target.value)
}
const onSearch = () =>{
getRecipe();
}
return (
<div className="App">
<Header search={search} onInputChange={onInputChange} onSearch={onSearch}/>
<div className="container"><Recipes recipes={recipes}/></div>
</div>
);
}
export default App;
Head.js
import React from 'react'
function Header(props) {
return (
<div className="jumbotron jumbotron-fluid">
<h1><span className="material-icons brand-icon">
fastfood
</span>FoodKhabari </h1>
<div className="input-group w-50 mx-auto">
<input type="text" className="form-control" placeholder="Search Your Recipe..." value={props.search} onChange={props.onInputChange} aria-label="Recipient's username" aria-describedby="basic-addon2"/>
<button type="button" className="btn btn-dark" onClick={props.onSearch}>Search Recipe</button>
</div>
</div>
)
}
export default Header
Recipe.js
import React from 'react'
import RecipeItems from './RecipeItems';
function Recipes(props) {
const{recipes} = props;
return (
<div className="row">
{recipes.map(recipe=>(
<RecipeItems
name = {recipe.recipe.label}
image= {recipe.recipe.image}
ingredientLines = {recipe.recipe.ingredientLines}
/>
))
}
</div>
)
}
export default Recipes
RecipeItem.js
import React from 'react'
function RecipeItems(props) {
const {name,image,ingredientLines} = props;
return (
<div className="col-md-3 mx-auto">
<div className="card py-3 text-center">
<img src={image} className="img-fluid w-50 mx-auto rounded-circle"/>
<div className="card-body">
<h5>{name}</h5>
</div>
<ul className="list-group list-group-flush">{ingredientLines.map(ingredient=>( <li
className="list-group-item">{ingredient}</li>)
) }</ul>
</div>
</div>
)
}
export default RecipeItems
Comments
Post a Comment