1

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.

1
  • 2
    You have to resolve the name to the actual class. You can do this by building a name -> class map and look up the class. Commented Nov 30, 2015 at 17:37

1 Answer 1

3

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]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.