React/JSX dynamic component names

前端 未结 1 2021
长情又很酷
长情又很酷 2020-12-11 08:02

I am looking to render a component based upon a string. Essentially, I am hoping to find the JSX equivalent to JavaScript\'s dynamic function name ability (parent[\"ch

相关标签:
1条回答
  • 2020-12-11 08:25

    JSX is just a nice syntax for function calls, so you need to have the actual functions to use a component. If you have an object that contains React components then you can render a component based on a string property. For example if you have an object called MyComponents (has to be uppercase for JSX) and that object has React components like MyComponents.SomeInput = React.CreateClass(...). Then you can use <MyComponents.SomeInput /> in your JSX.

    0 讨论(0)
提交回复
热议问题