Rendering to `document.body` in the examples is conveniently short, but it can
be misleading at the same time, especially for newcomers.
While it's possible to render React components to `document.body`, any 3rd
party scripts can also mess up with it, and it can have unintended consequences
and be source of difficult-to-trace bugs.
@ -24,7 +24,7 @@ var root = React.createElement('div');
To render a new tree into the DOM, you create `ReactElement`s and pass them to `React.render` along with a regular DOM `Element` (`HTMLElement` or `SVGElement`). `ReactElement`s are not to be confused with DOM `Element`s. A `ReactElement` is a light, stateless, immutable, virtual representation of a DOM `Element`. It is a virtual DOM.
To render a new tree into the DOM, you create `ReactElement`s and pass them to `React.render` along with a regular DOM `Element` (`HTMLElement` or `SVGElement`). `ReactElement`s are not to be confused with DOM `Element`s. A `ReactElement` is a light, stateless, immutable, virtual representation of a DOM `Element`. It is a virtual DOM.
React already has built-in factories for common HTML tags:
React already has built-in factories for common HTML tags:
@ -122,14 +122,14 @@ var element = <MyComponent />;
When this is passed to `React.render`, React will call the constructor for you and create a `ReactComponent`, which returned.
When this is passed to `React.render`, React will call the constructor for you and create a `ReactComponent`, which returned.
```javascript
```javascript
var component = React.render(element, document.body);
var component = React.render(element, document.getElementById('example'));
```
```
If you keep calling `React.render` with the same type of `ReactElement` and the same container DOM `Element` it always returns the same instance. This instance is stateful.
If you keep calling `React.render` with the same type of `ReactElement` and the same container DOM `Element` it always returns the same instance. This instance is stateful.
```javascript
```javascript
var componentA = React.render(<MyComponent/>, document.body);
var componentA = React.render(<MyComponent/>, document.getElementById('example'));
var componentB = React.render(<MyComponent/>, document.body);
var componentB = React.render(<MyComponent/>, document.getElementById('example'));