Dynamically Rendering a React component

后端 未结 5 949
暗喜
暗喜 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:40

    You should not put component slug in curly braces:

    var Hello = React.createClass({
        render: function() {
            return 
                {this.props.component.value}
            ;
        }
    });
    
    React.renderComponent(, document.body);
    

    Here is a working fiddle: http://jsfiddle.net/kb3gN/6668/

    Also, you can find JSX Compiler helpful for debugging these kind of errors: http://facebook.github.io/react/jsx-compiler.html

提交回复
热议问题