You need to first prepare a set of elements for display, and only then display them in the DOM tree through ReactDOM.render . If you are not using JSX, then your code might look like this:
// Генерируем массив элементов для отображения. var children = []; for (var i = 1; i < 5; i++) { children.push(React.createElement('div', null, i)); } // Отрисовываем элементы в DOM. ReactDOM.render( React.createElement('div', null, children), document.getElementById('container') );
And here is a working example on JSFiddle.
If you need to draw a certain pre-existing array in the DOM, then instead of the for loop, you can use the Array.prototype.map function:
var items = [1, 2, 3, 4]; ReactDOM.render( React.createElement('div', null, items.map(function(item) { return React.createElement('div', null, item); })), document.getElementById('container') );
Well, if you use JSX (and ES6), then the code can be written even more elegantly:
const items = [1, 2, 3, 4]; ReactDOM.render( (<div>{items.map(item => <div>{item}</div>)}</div>), document.getElementById('container') );