getElementName()

Returns the name of the react element (tag name, functional component or class component).

getElementName(element: ReactNode): string

Arguments

element
The react element for getting its name.

Return Value

A string that is the name of the react element.

Examples

import React, { Component, JSX, ReactElement } from 'react';
import { getElementName } from 'react-children-utilities';

getElementName('<span />'); // Result: 'span'

const Example = (): ReactElement => <div>this is the inner content</div>;

getElementName(<Example />); // Result: 'Example'

class Example2 extends Component {
  public render(): JSX.Element {
    return <div />;
  }
}

getElementName(<Example2 />); // Result: 'Example2'