Re-rendering A Component
After the initial mounting of components, a re-rendering will occur when:
In the code example below ReactDOM.render(< App / >, app);
starts the first cascade of rendering, rendering <App />
and <Timer/>
. The next re-render occurs when the calls the setState()
component method, which causes <App />
and <Timer/>
to be re-rendered. Note the UI changes when the now
state is changed.
The next re-render occurs when the setTimeout()
is invoked and 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.