Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to render multiple children without JSX

Tags:

How to write this without using JSX?

 var CommentBox = React.createClass({
  render: function() {
    return (
      <div className="commentBox">
        <h1>Comments</h1>
        <CommentList />
        <CommentForm />
      </div>
    );
  }
});

This comes from the react.js tutorial: http://facebook.github.io/react/docs/tutorial.html

I know I can do the following:

return (
   React.createElement('div', { className: "commentBox" },
        React.createElement('h1', {}, "Comments")
)

But this only adds one element. How can I add more next to one another.

like image 584
Demian Kasier Avatar asked Dec 04 '14 09:12

Demian Kasier


1 Answers

You can use the online Babel REPL (https://babeljs.io/repl/) as a quick way to convert little chunks of JSX to the equivalent JavaScript.

var CommentBox = React.createClass({displayName: 'CommentBox',
  render: function() {
    return (
      React.createElement("div", {className: "commentBox"}, 
        React.createElement("h1", null, "Comments"), 
        React.createElement(CommentList, null), 
        React.createElement(CommentForm, null)
      )
    );
  }
});

It's also handy for checking what the transpiler outputs for the ES6 transforms it supports.

like image 88
Jonny Buchanan Avatar answered Oct 10 '22 18:10

Jonny Buchanan