The Virtual DOM

When you define a component's render method and invoke the React.createElement method, you are not actually rendering anything in the document (you are not even creating DOM elements).

It is only through the React.render function that the representation created by invoking these React.createElement calls are effectively converted into real DOM elements and attached to the document.

This representation, defined by ReactElements, is what React calls the Virtual DOM. And ReactElement must not be confused with DOM elements; it is instead a light, stateless, immutable, virtual representation of a DOM element.

So why did React get into the trouble of creating a new way of representing the DOM? The answer here is performance.

As browsers ...

Get Jasmine JavaScript Testing - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.