Skip to main content

Updating Element

The simplest way to update the element is create a new Element and pass it to ReactDOM.render:

function tick() {
const element = (
<div>
<h1>Hello, world!</h1>
<h2>It is {new Date().toLocaleTimeString()}.</h2>
</div>
);
ReactDOM.render(element, document.getElementById('root'));
}

setInterval(tick, 1000);

Try it on CodePen

React only updates what's necessary.

reactjs.org