react-display-name
utility to return a react components display name
Last updated 5 years ago by jurassix .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install react-display-name 
SYNC missed versions from official npm registry.
npm install --save react-display-name

Get the displayName from a Component. This is a common pattern with React Higher Order Components (HoCs). This is a simple reusable utility to get the name of a component.

Usage:

import {expect} from 'chai';
import React, {Component} from 'react';
import getDisplayName from 'react-display-name';

const container = (WrappedComponent) => {
  class Container extends Component {
    static displayName = `Container(${getDisplayName(WrappedComponent)})`;
    render() {
      return (
        <WrappedComponent />
      );
    }
  }
  return Container;
}

class HelloWorld extends Component {
  render() {
    return (
      <div>Hello</div>
    );
  }
}

const HelloWorldPrime = container(HelloWorld);

expect(getDisplayName(HelloWorldPrime)).to.equal('Container(HelloWorld)');
expect(HelloWorldPrime.displayName).to.equal('Container(HelloWorld)');

Current Tags

  • 0.2.5                                ...           latest (5 years ago)

6 Versions

  • 0.2.5                                ...           5 years ago
  • 0.2.4                                ...           7 years ago
  • 0.2.3                                ...           7 years ago
  • 0.2.0                                ...           9 years ago
  • 0.1.1                                ...           9 years ago
  • 0.0.1                                ...           9 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (16)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |