Created
May 14, 2018 07:27
-
-
Save imparvez/6b988c60ed9a26815bcd02a14a0209b0 to your computer and use it in GitHub Desktop.
Food List React App
This file contains hidden or 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, { Component } from 'react'; | |
import axios from 'axios'; | |
import RecipeCard from './components/RecipeCard'; | |
import './App.css'; | |
class App extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
meal: {} | |
} | |
} | |
componentDidMount(){ | |
const URL = 'https://www.themealdb.com/api/json/v1/1/latest.php'; | |
axios.get(URL) | |
.then(res => { | |
const meal = res.data.meals; | |
if(typeof meal === 'object'){ | |
this.setState({ meal }); | |
} | |
}) | |
.catch(error => { | |
console.log(error); | |
}); | |
} | |
render() { | |
var data = this.state.meal; | |
return ( | |
<div className="App"> | |
{data.length > 0 && <RecipeCard meals={data} />} | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment