I have several components.
formFields/index.js
export {default as description} from './description/description.component'
export {default as title} from './title/title.component'
I import them and get a list of FormFields in mainComponent
import * as FormFields from '../formFields'
How can I use them in render function?
This is one of my failed attempts:
import * as FormFields from '../formFields'
render() {
let properties = ['description', 'title'];
let getComponent = (type) => {
let formElement = FormFields[type]
return <formElement/>
}
return (
<div>
{properties.map((property, i) => {
return (
<div key={i}>
{getComponent(property)}
</div>
);
})}
</div>
)
}
This experiment is successful:
render() {
let EditComponent = FormFields['description']
return (
<div>
<EditComponent/>
</div>
)
}