Dynamically Rendering a React component

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

    Edit: Maybe you forgot to add /** @jsx React.DOM */ at the beginning of js?

    You can use React.DOM though:

    render: function() {
      return React.DOM[this.props.component.slug](null, this.props.component.value);
    }
    

    http://jsbin.com/rerehutena/2/edit?html,js,output

    I am not a React expert, but I think every component should be construct with a specific tag at the beginning. So it could present a clear purpose itself.

提交回复
热议问题