forked from reactjs/react.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganized codepen folder further to support nesting
- Loading branch information
Showing
9 changed files
with
145 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ content/* | |
public/* | ||
|
||
# Ignore examples | ||
examples/* | ||
codepen/* |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
); |
52 changes: 52 additions & 0 deletions
52
codepen/components-and-props/extracting-components-continued.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function Welcome(props) { | ||
return <h1>Hello, {props.name}</h1>; | ||
} | ||
|
||
const element = <Welcome name="Sara" />; | ||
ReactDOM.render( | ||
element, | ||
document.getElementById('root') | ||
); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1535,7 +1535,7 @@ bowser@^1.6.0: | |
version "1.7.1" | ||
resolved "https://registry.yarnpkg.com/bowser/-/bowser-1.7.1.tgz#a4de8f18a1a0dc9531eb2a92a1521fb6a9ba96a5" | ||
|
||
brace-expansion@^1.1.7: | ||
brace-expansion@^1.0.0, brace-expansion@^1.1.7: | ||
version "1.1.8" | ||
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.8.tgz#c07b211c7c952ec1f8efd51a77ef0d1d3990a292" | ||
dependencies: | ||
|
@@ -6367,6 +6367,12 @@ minimalistic-crypto-utils@^1.0.0, minimalistic-crypto-utils@^1.0.1: | |
dependencies: | ||
brace-expansion "^1.1.7" | ||
|
||
[email protected]: | ||
version "3.0.3" | ||
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.3.tgz#2a4e4090b96b2db06a9d7df01055a62a77c9b774" | ||
dependencies: | ||
brace-expansion "^1.0.0" | ||
|
||
[email protected]: | ||
version "0.0.8" | ||
resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" | ||
|
@@ -8054,6 +8060,12 @@ rechoir@^0.6.2: | |
dependencies: | ||
resolve "^1.1.6" | ||
|
||
recursive-readdir@^2.2.1: | ||
version "2.2.1" | ||
resolved "https://registry.yarnpkg.com/recursive-readdir/-/recursive-readdir-2.2.1.tgz#90ef231d0778c5ce093c9a48d74e5c5422d13a99" | ||
dependencies: | ||
minimatch "3.0.3" | ||
|
||
redbox-react@^1.3.6: | ||
version "1.5.0" | ||
resolved "https://registry.yarnpkg.com/redbox-react/-/redbox-react-1.5.0.tgz#04dab11557d26651bf3562a67c22ace56c5d3967" | ||
|