Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Given an array of react class names, I want to create a component using that class name.
I tried:
React.createElement(name);
But got an HTML element with name (ex: <MyReactClass/>), but not an actual react component which is what I need.
<MyReactClass/>
name -> class
You need to map the names to the actual classes, like as @Felix Kling mentioned. The are several ways to do this. One such way:
var classes = { "name1": require('./Class1'), "name2": require('./Class2'), ... }; ... React.createElement(classes[name]);
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
name -> classmap and look up the class.