I am writing a webpage which dynamically renders elements from a database, with each one having its own state. To choose what element is rendered, I used a switch-case like this:
switch (this.state.type) {
case 'textarea':
element = <textarea {...this.state} />
break
...
default:
element = <input {...this.state} />
}
What I would like to do is have a nice way of choosing which element is rendered, like this:
switch (this.state.type) {
case 'textarea':
tag = 'textarea'
break
...
default:
tag = 'input'
}
element = <{tag} {...this.state} />
Is there a way to something similar to this in React?