Skip to content

Instantly share code, notes, and snippets.

@llkats
Created May 16, 2014 23:48
Show Gist options
  • Save llkats/0e378ca0bd702435fb87 to your computer and use it in GitHub Desktop.
Save llkats/0e378ca0bd702435fb87 to your computer and use it in GitHub Desktop.
dynamic react element creation!
var tagname = 'p';
var aView = React.createClass({
render: function() {
return React.DOM[tagname]({}, 'here is some content');
}
});
@tameraydin
Copy link

do you know if it is possible to accomplish this in JSX syntax?

@TSMMark
Copy link

TSMMark commented Sep 19, 2015

@tameraydin I couldn't figure how to do this in JSX, but the cool thing about JSX is you can interchange JSX with raw JS whenever you like; so this is valid, for example:

(
  <div>
    {React.DOM[tagname](null, "here is some content")}
  </div>
)

and this:

(
  <div>
    {
      React.DOM[tagname](null,
        "here is some content",
        <p>Some more content</p>
      )
    }
  </div>
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment