class ContactInfo extends React.Component {
render(){
return (
<div>{this.props.contact.name} {this.props.contact.phone}</div>
);
}
};
class Contact extends React.Component {
constructor(props) {
super(props);
this.state = {
contactData : [
{name : 'jeewoo', phone : '1234'},
{name : 'jeesoo', phone : '5678'},
{name : 'jeewon', phone : '8765'},
{name : 'jeejee', phone : '4321'}
]
}
}
render(){
const mapToComponent = (data) => {
return data.map((contact,i)=>{
return (<ContactInfo contact={contact} key={i}/>);
});
};
return (
//mapToComponent Function 호출
<div>{mapToComponent(this.state.contactData)}</div>
);
}
};
class App extends React.Component {
render() {
return (
<Contact />
);
}
};
ReactDOM.render(
<App></App>,
document.getElementById("root")
);