import React from 'react';
function Potato() {
return <h1>I like Potato</h1>;
}
function App() {
return (
<div>
<h1>Hello!</h1>
<Potato />
</div>
);
}
export default App;
<Food fav = "kimchi" />
import React from 'react';
function Food({fav}) { //{fav} 대신 props라 쓰고
return <h1>I like {fav}</h1>; //여기에 fav대신 props.fav로 쓸 수 있다.
}
function App() {
return (
<div>
<h1>Hello!</h1>
<Food fav="kimchi" />
</div>
);
}
export default App;
fav = "kimchi" -> component에 넣게 되는 것들을 props라고 하자.
props는 argument로 간다.
import React from 'react';
function Food({name,picture}) {
return <div>
<h2>I like {name}</h2>
<img src = {picture} />
</div>
}
const foodIlike = [
{
name: "Kimchi",
image:
"http://aeriskitchen.com/wp-content/uploads/2008/09/kimchi_bokkeumbap_02-.jpg"
},
{
name: "Samgyeopsal",
image:
"https://3.bp.blogspot.com/-hKwIBxIVcQw/WfsewX3fhJI/AAAAAAAAALk/yHxnxFXcfx4ZKSfHS_RQNKjw3bAC03AnACLcBGAs/s400/DSC07624.jpg"
},
{
name: "Bibimbap",
image:
"http://cdn-image.myrecipes.com/sites/default/files/styles/4_3_horizontal_-_1200x900/public/image/recipes/ck/12/03/bibimbop-ck-x.jpg?itok=RoXlp6Xb"
},
{
name: "Doncasu",
image:
"https://s3-media3.fl.yelpcdn.com/bphoto/7F9eTTQ_yxaWIRytAu5feA/ls.jpg"
},
{
name: "Kimbap",
image:
"http://cdn2.koreanbapsang.com/wp-content/uploads/2012/05/DSC_1238r-e1454170512295.jpg"
}
];
function App() {
return (
<div>
{foodIlike.map(dish => <Food name ={dish.name} picture={dish.image}/>)}
</div>
);
}
export default App;
const foodIlike = [
{
id : 1,
name: "Kimchi",
image:
"http://aeriskitchen.com/wp-content/uploads/2008/09/kimchi_bokkeumbap_02-.jpg"
},
{
id : 2,
name: "Samgyeopsal",
image:
"https://3.bp.blogspot.com/-hKwIBxIVcQw/WfsewX3fhJI/AAAAAAAAALk/yHxnxFXcfx4ZKSfHS_RQNKjw3bAC03AnACLcBGAs/s400/DSC07624.jpg"
},
{
id : 3,
name: "Bibimbap",
image:
"http://cdn-image.myrecipes.com/sites/default/files/styles/4_3_horizontal_-_1200x900/public/image/recipes/ck/12/03/bibimbop-ck-x.jpg?itok=RoXlp6Xb"
},
{
id : 4,
name: "Doncasu",
image:
"https://s3-media3.fl.yelpcdn.com/bphoto/7F9eTTQ_yxaWIRytAu5feA/ls.jpg"
},
{
id : 5,
name: "Kimbap",
image:
"http://cdn2.koreanbapsang.com/wp-content/uploads/2012/05/DSC_1238r-e1454170512295.jpg"
}
];
function App() {
return (
<div>
{foodIlike.map(dish => <Food key={dish.id} name ={dish.name} picture={dish.image} rating={dish.rating}/>)}
</div>
);
}
import React from 'react';
import PropTypes from "prop-types";
const foodIlike = [
{
id : 1,
name: "Kimchi",
image:
"http://aeriskitchen.com/wp-content/uploads/2008/09/kimchi_bokkeumbap_02-.jpg",
rating : 4
},
{
id : 2,
name: "Samgyeopsal",
image:
"https://3.bp.blogspot.com/-hKwIBxIVcQw/WfsewX3fhJI/AAAAAAAAALk/yHxnxFXcfx4ZKSfHS_RQNKjw3bAC03AnACLcBGAs/s400/DSC07624.jpg",
rating : 5
},
{
id : 3,
name: "Bibimbap",
image:
"http://cdn-image.myrecipes.com/sites/default/files/styles/4_3_horizontal_-_1200x900/public/image/recipes/ck/12/03/bibimbop-ck-x.jpg?itok=RoXlp6Xb",
rating : 5.4
},
{
id : 4,
name: "Doncasu",
image:
"https://s3-media3.fl.yelpcdn.com/bphoto/7F9eTTQ_yxaWIRytAu5feA/ls.jpg",
rating : 5.5
},
{
id : 5,
name: "Kimbap",
image:
"http://cdn2.koreanbapsang.com/wp-content/uploads/2012/05/DSC_1238r-e1454170512295.jpg",
rating : 4.7
}
];
function Food({name,picture,rating}) {
return (<div>
<h2>I like {name}</h2>
<h4>{rating}/5.0</h4>
<img src = {picture} alt={name}/>
</div>);
}
Food.propTypes = { //propTypes 첫글자가 소문자여야 한다.
name : PropTypes.string.isRequired,
picture : PropTypes.string.isRequired,
rating : PropTypes.number.isRequired
};
function App() {
return (
<div>
{foodIlike.map(dish => <Food key={dish.id} name ={dish.name} picture={dish.image} rating={dish.rating}/>)}
</div>
);
}
export default App;