diff --git a/src/App.js b/src/App.js
index 203067e..23d33bf 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,18 +1,67 @@
-import React, { Component } from 'react';
-import logo from './logo.svg';
-import './App.css';
+import React, { Component } from "react";
+import "./App.css";
+import { Recipe } from "./Components/Recipe";
+import { Search } from "./Components/Search";
+
+const APP_ID = "fc6f60d3";
+const APP_KEY = "bd93df5272c4eb7bc29fd506cea911b9";
+const BASE_ENDPOINT = `https://api.edamam.com/search?app_id=${APP_ID}&app_key=${APP_KEY}`;
+
+const withErrorHandling = WrappedComponent => ({ error, children }) => {
+ return (
+
+ {error ? Error! {error}
: children}
+
+ );
+};
+
+const ErrorWrapper = withErrorHandling(({ children }) =>
{children}
);
class App extends Component {
+ constructor() {
+ super();
+ this.state = {
+ error: false,
+ recipeList: [],
+ query: ""
+ };
+ }
+
+ callApiWithQuery = query => {
+ fetch(`${BASE_ENDPOINT}&q=${query}`)
+ .then(response => response.json())
+ .then(
+ response =>
+ response.hits.length > 0
+ ? this.setState({ recipeList: [...response.hits], error: null })
+ : this.setState({ error: "Nothing to see here!", recipeList: "" })
+ )
+ .catch(error => this.setState({ error: error.message }));
+ };
+
+ componentDidMount() {
+ this.callApiWithQuery("cake");
+ }
+
+ updateSearch = e => {
+ this.setState({ query: e.target.value });
+ this.callApiWithQuery(this.state.query);
+ };
+
render() {
return (
-
-
- Welcome to React
-
-
- To get started, edit src/App.js
and save to reload.
-
+
+
+ {this.state.recipeList &&
+ this.state.recipeList.map(recipe => (
+
+ ))}
+
);
}
diff --git a/src/Components/Recipe.js b/src/Components/Recipe.js
new file mode 100644
index 0000000..19e3383
--- /dev/null
+++ b/src/Components/Recipe.js
@@ -0,0 +1,11 @@
+import React from "react";
+
+export const Recipe = ({ name, calories }) => {
+ return (
+
+ Name: {name}
+
+ Calories: {calories}
+
+ );
+};
diff --git a/src/Components/Search.js b/src/Components/Search.js
new file mode 100644
index 0000000..6c6d5e6
--- /dev/null
+++ b/src/Components/Search.js
@@ -0,0 +1,5 @@
+import React from "react";
+
+export const Search = ({ onChange, value }) => {
+ return onChange(e)} />;
+};
diff --git a/yarn.lock b/yarn.lock
index 4713834..164bfc4 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -5126,7 +5126,7 @@ react-dev-utils@^5.0.0:
strip-ansi "3.0.1"
text-table "0.2.0"
-react-dom@16.2.0:
+react-dom@^16.2.0:
version "16.2.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.2.0.tgz#69003178601c0ca19b709b33a83369fe6124c044"
dependencies:
@@ -5183,7 +5183,7 @@ react-scripts@1.1.1:
optionalDependencies:
fsevents "^1.1.3"
-react@16.2.0:
+react@^16.2.0:
version "16.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.2.0.tgz#a31bd2dab89bff65d42134fa187f24d054c273ba"
dependencies: