How to get the string name of a class of a React Native component?

I want the print class name with a string format to respond to native programmatically. Can someone tell me about this, how can I do this?

+6
source share
1 answer

In JavaScript, you can get the class name with instance.constructor.name .

 class Demo extends React.Component { componentDidMount(){ console.log(this.constructor.name); // "Demo" } } 

For JSX components, you can use instance.type.displayName . For instance:

 let text = <Text></Text>; console.log(text.type.displayName) // "Text" 
+7
source

Source: https://habr.com/ru/post/1013273/


All Articles