class App extends React.Component {
render() {
return (
<div>
<Friend
name="Elon"
hobby={["Dancing", "Drawing", "Singing"]}
/>
<Friend
name="Linda"
hobby={["Piano", "Reading a book", "Gaming"]}
/>
</div>
)
}
}
ReactDOM.render(<App />, document.getElementById('root'));
option 1
class Friend extends React.Component {
render() {
const { name, hobby } = this.props;
return (
<div>
<h1>{name}</h1>
<ul>
{hobby.map(h => <li>{h}</li>)}
</ul>
</div>
);
}
}
option 2
class Friend extends React.Component {
render() {
const { name, hobby } = this.props;
const list = hobby.map(h => <li>{h}</li>)
return (
<div>
<h1>{name}</h1>
<ul>
{list}
</ul>
</div>
);
}
}
'react' 카테고리의 다른 글
Props : styling (0) | 2020.06.13 |
---|---|
Props : default props (0) | 2020.06.13 |
Props : slot machine exercise (0) | 2020.06.13 |
Props : types of props (0) | 2020.06.13 |
Introducing Props! and more.. (0) | 2020.06.13 |