9 changed files with 145 additions and 11 deletions
@ -0,0 +1,18 @@ |
|||
function Welcome(props) { |
|||
return <h1>Hello, {props.name}</h1>; |
|||
} |
|||
|
|||
function App() { |
|||
return ( |
|||
<div> |
|||
<Welcome name="Sara" /> |
|||
<Welcome name="Cahal" /> |
|||
<Welcome name="Edite" /> |
|||
</div> |
|||
); |
|||
} |
|||
|
|||
ReactDOM.render( |
|||
<App />, |
|||
document.getElementById('root') |
|||
); |
@ -0,0 +1,52 @@ |
|||
function formatDate(date) { |
|||
return date.toLocaleDateString(); |
|||
} |
|||
|
|||
function Avatar(props) { |
|||
return ( |
|||
<img className="Avatar" |
|||
src={props.user.avatarUrl} |
|||
alt={props.user.name} /> |
|||
); |
|||
} |
|||
|
|||
function UserInfo(props) { |
|||
return ( |
|||
<div className="UserInfo"> |
|||
<Avatar user={props.user} /> |
|||
<div className="UserInfo-name"> |
|||
{props.user.name} |
|||
</div> |
|||
</div> |
|||
); |
|||
} |
|||
|
|||
function Comment(props) { |
|||
return ( |
|||
<div className="Comment"> |
|||
<UserInfo user={props.author} /> |
|||
<div className="Comment-text"> |
|||
{props.text} |
|||
</div> |
|||
<div className="Comment-date"> |
|||
{formatDate(props.date)} |
|||
</div> |
|||
</div> |
|||
); |
|||
} |
|||
|
|||
const comment = { |
|||
date: new Date(), |
|||
text: 'I hope you enjoy learning React!', |
|||
author: { |
|||
name: 'Hello Kitty', |
|||
avatarUrl: 'http://placekitten.com/g/64/64' |
|||
} |
|||
}; |
|||
ReactDOM.render( |
|||
<Comment |
|||
date={comment.date} |
|||
text={comment.text} |
|||
author={comment.author} />, |
|||
document.getElementById('root') |
|||
); |
@ -0,0 +1,40 @@ |
|||
function formatDate(date) { |
|||
return date.toLocaleDateString(); |
|||
} |
|||
|
|||
function Comment(props) { |
|||
return ( |
|||
<div className="Comment"> |
|||
<div className="UserInfo"> |
|||
<img className="Avatar" |
|||
src={props.author.avatarUrl} |
|||
alt={props.author.name} /> |
|||
<div className="UserInfo-name"> |
|||
{props.author.name} |
|||
</div> |
|||
</div> |
|||
<div className="Comment-text"> |
|||
{props.text} |
|||
</div> |
|||
<div className="Comment-date"> |
|||
{formatDate(props.date)} |
|||
</div> |
|||
</div> |
|||
); |
|||
} |
|||
|
|||
const comment = { |
|||
date: new Date(), |
|||
text: 'I hope you enjoy learning React!', |
|||
author: { |
|||
name: 'Hello Kitty', |
|||
avatarUrl: 'http://placekitten.com/g/64/64' |
|||
} |
|||
}; |
|||
ReactDOM.render( |
|||
<Comment |
|||
date={comment.date} |
|||
text={comment.text} |
|||
author={comment.author} />, |
|||
document.getElementById('root') |
|||
); |
@ -0,0 +1,9 @@ |
|||
function Welcome(props) { |
|||
return <h1>Hello, {props.name}</h1>; |
|||
} |
|||
|
|||
const element = <Welcome name="Sara" />; |
|||
ReactDOM.render( |
|||
element, |
|||
document.getElementById('root') |
|||
); |
Loading…
Reference in new issue