Skip to content
Snippets Groups Projects
Commit f5520ef3 authored by Mertta Hätinen's avatar Mertta Hätinen
Browse files

Do excercise 2.1 - 2.2

parent 1f5ace56
No related branches found
No related tags found
No related merge requests found
import React from 'react' import React from 'react'
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
const Phonebook = (props) => {
return (
<div>
<Header title={props.phonebook.name}/>
<Contents contacts={props.phonebook.contacts}/>
<NumberOfEntries number={props.phonebook.contacts.length} />
</div>
)
}
const NumberOfEntries = (props) => <p>Total number of entries {props.number}</p>
const Header = (props) => <h1>{props.title}</h1> const Header = (props) => <h1>{props.title}</h1>
const Contents = (props) => { const Contents = (props) => {
return ( return (
<div> <div>
<Entry contact={props.contacts[0]}/> {props.contacts.map(contact => (
<Entry contact={props.contacts[1]}/> <Entry contact={contact} key={contact.id}/>
<Entry contact={props.contacts[2]}/> ))}
</div> </div>
) )
} }
...@@ -21,27 +33,31 @@ const Entry = (props) => { ...@@ -21,27 +33,31 @@ const Entry = (props) => {
) )
} }
const App = () => { const App = () => { //Älä muuta
const title = 'Superadvanced web phonebook app' const phonebook = {
const contacts = [ name: 'Superadvanced phonebook app',
contacts: [
{ {
name: 'John Doe', name: 'John Doe',
phonenumber: '358401234567' phonenumber: '358401234567',
id: 1
}, },
{ {
name: 'Jane Doe', name: 'Jane Doe',
phonenumber: '44551234567' phonenumber: '44551234567',
id: 2
}, },
{ {
name: 'Foo bar', name: 'Foo bar',
phonenumber: '000' phonenumber: '000',
id: 3
} }
] ]
}
return ( return (
<div> <div>
<Header title="kikkeli" /> <Phonebook phonebook={phonebook} />
<Contents contacts={contacts} />
</div> </div>
) )
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment