How do you update rendered elements?

You can update UI(represented by rendered element) by passing the newly created element to ReactDOM's render method.

For example, lets take a ticking clock example, where it updates the time by calling render method multiple times,

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

May 18, 2022