Seppo420 Seppo420 -4 years ago 102
React JSX Question

How to get factory of an element when element class is not known

So, I have a React element and I need to create more elements of the same class. However the class of the element is not known, I just have an instance of the element.

React.createFactory(element) returns undefined. element.proto seems to be a ReactClassComponent but haven't figured out how to make a factory out of it. React.createFactory(element.proto) returns undefined as well.

Answer Source

Use

React.createFactory(element.__proto__.constructor)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download