8000 add render-jsx-to-dom.md · learnreactjs/learnreactjs@50b04a7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 50b04a7

Browse files
committed
add render-jsx-to-dom.md
1 parent 69f0f4d commit 50b04a7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

content/jsx/render-jsx-to-dom.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Rendering JSX to DOM
2+
3+
The `ReactDOM.render()` function can be used to render JSX to the DOM. Actually, after Babel transforms the JSX all it is doing is rendering nodes created by `React.createElement()`.
4+
5+
In the example I am rendering a `<option>` element to the DOM using JSX.
6+
7+
<p data-height="265" data-theme-id="dark" data-slug-hash="odJLPe" data-default-tab="js,result" data-user="Bunlong" data-embed-version="2" data-pen-title="odJLPe" class="codepen">See the Pen <a href="https://codepen.io/Bunlong/pen/odJLPe/">odJLPe</a> by Bunlong (<a href="https://codepen.io/Bunlong">@Bunlong</a>) on <a href="https://codepen.io">CodePen</a>.</p>
8+
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
9+
10+
Once rendered to the DOM, the HTML will look like so:
11+
12+
```javascript
13+
<body>
14+
<div id="app"><option value="1" data-reactid=".0">one</li></div>
15+
</body>
16+
```
17+
18+
Babel is taking the JSX in your JavaScript files transforming it to React nodes (React.createElement()) then using these nodes created by React (the Virtual DOM) as a template for creating a real html DOM branch. The part where the React nodes are turned into the real DOM nodes and added to the DOM in an HTML page occurs when ReactDOM.render() is called.

0 commit comments

Comments
 (0)
0