10000 add re-render-a-component.md · learnreactjs/learnreactjs@b0dbe8c · GitHub
[go: up one dir, main page]

Skip to content

Commit b0dbe8c

Browse files
committed
add re-render-a-component.md
1 parent e2218ed commit b0dbe8c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Re-rendering A Component
2+
3+
You would realize that calling `ReactDom.render()` is the initial of the rendering of a component and all sub components.
4+
5+
After the initial mounting of components, a re-rendering will occur when:
6+
7+
* A component's `setState()` method is called.
8+
* A component's `forceUpdate()` method is called.
9+
10+
In the example below `ReactDOM.render(< App / >, app);` starts the first cascade of rendering, rendering `<App />` and `<Timer/>`. The next re-render occurs when the `setInterval()` calls the `setState()` component method, which causes `<App />` and `<Timer/>` to be re-rendered. Note the UI changes when the `now state` is changed.
11+
12+
<p data-height="265" data-theme-id="dark" data-slug-hash="odmzaM" data-default-tab="js,result" data-user="Bunlong" data-embed-version="2" data-pen-title="odmzaM" class="codepen">See the Pen <a href="https://codepen.io/Bunlong/pen/odmzaM/">odmzaM</a> by Bunlong (<a href="https://codepen.io/Bunlong">@Bunlong</a>) on <a href="https://codepen.io">CodePen</a>.</p>
13+
<script async src="https://static.codepen.io/assets/embed/ei.js"></script>
14+
15+
The next re-render occurs when the `setTimeout()` is invoked and `this.forceUpdate()` is called. Note that simply updating the state (i.e. `this.state.now = 'foo'`;) does not cause a re-render. I set the state using `this.state`, and then I have to call `this.forceUpdate()` so the component will re-render with the new state.

0 commit comments

Comments
 (0)
0