Created
September 6, 2020 19:55
-
-
Save AppleCEO/15f557725056f3598ac851430edd783f to your computer and use it in GitHub Desktop.
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 from "react"; | |
import "./styles.css"; | |
export default function App() { | |
return <Contact /> | |
} | |
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:'Abet',phone:'010-0000-0001'}, | |
{name:'Betty',phone:'010-0000-0002'}, | |
{name:'Charlie',phone:'010-0000-0003'}, | |
{name:'David',phone:'010-0000-0004'} | |
] | |
} | |
} | |
render() { | |
const mapToComponent = (data) => { | |
return data.map((contact, i) => { | |
return (<ContactInfo contact={contact} key={i}/>); | |
}); | |
}; | |
return ( | |
<div> | |
{mapToComponent(this.state.contactData)} | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment