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

Skip to content

Commit fd84f82

Browse files
committed
add render-to-dom.md
1 parent 757291e commit fd84f82

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

content/react-node/render-to-dom.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Rendering to DOM
2+
3+
React provides the `ReactDOM.render()` function from `react-dom js` that can be used to render React nodes to the DOM. We've already seen this `render()` function in use in this chapter.
4+
5+
In the example below, using `ReactDOM.render()`, the `<option>` and `<foo-bar>` React nodes are rendered to the DOM.
6+
7+
<p data-height="265" data-theme-id="dark" data-slug-hash="xjJBeQ" data-default-tab="js,result" data-user="Bunlong" data-embed-version="2" data-pen-title="xjJBeQ" class="codepen">See the Pen <a href="https://codepen.io/Bunlong/pen/xjJBeQ/">xjJBeQ</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 be:
11+
12+
```
13+
<body>
14+
<div id="app1"><option value="1" data-reactid=".0">one</option></div>
15+
<div id="app2"><foo-bar classname="bar" children="foo" data-reactid=".1">foo</foo-bar></div>
16+
</body>
17+
```
18+
19+
The `ReactDOM.render()` function is initially how you get the React nodes to the Virtual DOM, then to the HTML DOM.

0 commit comments

Comments
 (0)
0