forked from theindianappguy/recipe-app-reactjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
51 lines (43 loc) · 1.33 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import Axios from "axios";
import { useState } from "react";
import "./app.css";
import RecipeTile from "./components/recipe-tile";
function App() {
const [query, setquery] = useState("");
const [recipes, setrecipes] = useState([]);
const YOUR_APP_ID = `82e453da`;
const YOUR_APP_KEY = "3bb5d1a3b992f408b9003effd74c9c22";
const url = `https://api.edamam.com/search?q=${query}&app_id=${YOUR_APP_ID}&app_key=${YOUR_APP_KEY}`;
const getRecipeInfo = async () => {
var result = await Axios.get(url);
setrecipes(result.data.hits);
console.log(result.data.hits);
};
const onSubmit = (e) => {
e.preventDefault();
getRecipeInfo();
};
return (
<div className="app">
<h1 onClick={getRecipeInfo}>Food Recipe Plaza 🍔</h1>
<form className="app__searchForm" onSubmit={onSubmit}>
<input
className="app__input"
type="text"
placeholder="enter ingridient"
autoComplete="Off"
value={query}
onChange={(e) => setquery(e.target.value)}
/>
<input className="app__submit" type="submit" value="Search" />
</form>
<div className="app__recipes">
{recipes !== [] &&
recipes.map((recipe) => {
return <RecipeTile recipe={recipe} />;
})}
</div>
</div>
);
}
export default App;