l2silver
l2silver

Reputation: 3439

React generate components with dynamic tags babel es6

I would like to be able to change the tag of a React component parent node like so

React.createClass({
    render: function(){
        const tagName = this.props.tagName;
        const domTag = tagName ? React.DOM[tagName] : React.DOM.div;
        return <domTag />
    }
})

drawing reference from this question and answer

Dynamically Rendering a React component

But when I use the above method, my react component tag type is domTag...

Any ideas? I'm webpack and babel to compile the code.

Upvotes: 1

Views: 339

Answers (1)

l2silver
l2silver

Reputation: 3439

The answer is ...

you just pass a string, and not the DOM function, ie.

const TagName = 'input';
return <TagName />

Upvotes: 2

Related Questions