forked from alleyinteractive/react-fundamentals
-
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.
- Loading branch information
Nicole Arnold
committed
May 14, 2021
1 parent
032da75
commit 9b6dfe7
Showing
1 changed file
with
45 additions
and
8 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 |
---|---|---|
|
@@ -6,26 +6,63 @@ | |
<script src="https://unpkg.com/[email protected]/umd/react.development.js"></script> | ||
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js"></script> | ||
|
||
<!-- 💣 remove this line | ||
<script src="https://unpkg.com/@babel/[email protected]/babel.js"></script> | ||
💣 remove this line --> | ||
|
||
<script type="module"> | ||
<script type="text/babel"> | ||
// 🐨 on the script tag above, change `type="module"` | ||
// to `type="text/babel"` so babel will compile this code for the browser to run. | ||
|
||
// 🐨 re-implement this using JSX! | ||
const element = React.createElement('div', { | ||
className: 'container', | ||
children: 'Hello World', | ||
}) | ||
// const element = React.createElement('div', { | ||
// className: 'container', | ||
// children: 'Hello World', | ||
// }); | ||
|
||
const element = <div className="container">Hello World</div>; | ||
|
||
// 💰 there are a few subtle differences between JSX and HTML. One such | ||
// difference is how you apply a class to an element in JSX is by using | ||
// `className` rather than `class`! | ||
// 📜 You can learn the differences between JSX and HTML syntax from the React docs here: | ||
// https://reactjs.org/docs/dom-elements.html#differences-in-attributes | ||
|
||
ReactDOM.render(element, document.getElementById('root')) | ||
ReactDOM.render(element, document.getElementById('root')); | ||
</script> | ||
|
||
<!-- EXTRA CREDIT --> | ||
<div id="root2"></div> | ||
|
||
<script type="text/babel"> | ||
// See if you can figure out how to extract the className ("container") and children | ||
// ("Hello World") to variables and interpolate them in the JSX. | ||
// const className = 'container' | ||
// const children = 'Hello World' | ||
// const element = <div className="hmmm">how do I make this work?</div> | ||
|
||
const className = 'container' | ||
const children = 'Hello World' | ||
const element = <div className={className}>{children}</div>; | ||
|
||
ReactDOM.render(element, document.getElementById('root2')); | ||
</script> | ||
|
||
<!-- EXTRA CREDIT --> | ||
<div id="root3"></div> | ||
|
||
<script type="text/babel"> | ||
// See if you can figure out how to make that work with JSX. | ||
const children = 'Hello World'; | ||
const className = 'container'; | ||
const props = {children, className}; | ||
//const element = <div /> // how do I apply props to this div? | ||
|
||
function Div(props) { | ||
const {children, ...other} = props; | ||
return <div {...other}>{children}</div>; | ||
} | ||
const element = <Div {...props}/>; | ||
|
||
ReactDOM.render(element, document.getElementById('root3')); | ||
|
||
</script> | ||
</body> |