Skip to content

add more stable and backward-compatible stateless function detection #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@ import extendReactClass from './extendReactClass';
import wrapStatelessFunction from './wrapStatelessFunction';

let decoratorConstructor,
functionConstructor;
functionConstructor,
isReactComponent;

/**
* Determines if the given object has the signature of a class that inherits React.Component
*
* @param {*} Component
* @return {Boolean}
*/
isReactComponent = (Component) => {
return 'prototype' in Component && typeof Component.prototype.render === 'function';
};

/**
* When used as a function.
Expand All @@ -15,7 +26,7 @@ let decoratorConstructor,
functionConstructor = (Component, defaultStyles, options) => {
let decoratedClass;

decoratedClass = Component.isReactClass ?
decoratedClass = isReactComponent(Component) ?
extendReactClass(Component, defaultStyles, options) :
wrapStatelessFunction(Component, defaultStyles, options);

Expand Down
5 changes: 4 additions & 1 deletion test/reactCssModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('reactCssModules', () => {

Foo = class extends React.Component {
static displayName = 'Bar';
render () { return null; }
};

Foo = reactCssModules(Foo);
Expand All @@ -25,7 +26,9 @@ describe('reactCssModules', () => {
it('uses name for displayName', () => {
let Foo;

Foo = class Bar extends React.Component {};
Foo = class Bar extends React.Component {
render () { return null; }
};

Foo = reactCssModules(Foo);

Expand Down