Dynamically Rendering a React component

后端 未结 5 948
暗喜
暗喜 2020-12-04 07:44

In React JSX it does not appear to be possible to do something like this:

5条回答
  •  佛祖请我去吃肉
    2020-12-04 08:23

    As nilgun previously pointed out, the component slug should not be wrapped in curly braces.

    If you decide to store it in a variable, make sure it starts with a capital letter.

    Here is an example:

    var Home = React.createClass({
      render: function() {
        return (
          

    This is an input

    This is a text area

    ); } }); var CustomComponent = React.createClass({ render: function() { // make sure this var starts with a capital letter var InputType = this.props.inputType; return ; } }); React.render(, document.getElementById('container'));

    Here's a working fiddle: https://jsfiddle.net/janklimo/yc3qcd0u/

提交回复
热议问题