Skip to content

React.PropTypes.instanceOf always warns about invalid prop #2979

@pletcher

Description

@pletcher

Checked with React v0.12.2 running in Chrome 40.0.2214.93, Safari 8.0.2, and Firefox 35.0.

I'm able to reproduce this issue with the following:

// icon.jsx

var Icon = React.createClass({
  propTypes: {
    icon: React.PropTypes.string.isRequired
  },

  render: function() {
    return <span className={this.props.icon} />;
  }
});

module.exports = Icon;
// wrapper.jsx

var Icon = require('./icon.jsx');

var Wrapper = React.createClass({
  propTypes: {
    icon: React.PropTypes.instanceOf(Icon).isRequired,
  },

  render: function() {
    return <button className="btn">{this.props.icon}</button>;
  }
});

module.exports = Wrapper

When I render an instance of Wrapper as

// var icon = <Icon icon="some-icon" />

 <Wrapper icon={icon} />

I get the error

Warning: Invalid prop `icon` supplied to `Wrapper`, expected instance of `<<anonymous>>`. Check the render method of `[the parent component]`.

(I was also able to reproduce the issue here: http://jsbin.com/necequvimi/2/ )

It seems like the instanceOf prop-type checker isn't working as expected, but maybe I've missed something.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions