Cotten
Cotten

Reputation: 9077

React.PropTypes.element don't accept React.DOM.input etc

Concider this:

MyComponent = React.createFactory React.createClass
  displayName: 'MyComponent'
  propTypes:
    comp: React.PropTypes.element

  render: ->
    div {},
      this.props.comp {id: 'dummy1'}

AppView = React.createClass
  render: ->
    MyComponent {comp: React.DOM.input}

This throws the following error:

Warning: Failed propType: Invalid prop `comp` supplied to `MyComponent`,
expected a ReactElement. Check the render method of `Radium(AppView)`.

Am I missunderstanding the docs https://facebook.github.io/react/docs/reusable-components.html ? Is React.DOM.input not an "element"?

(React version 0.13.3)

Upvotes: 1

Views: 1190

Answers (1)

jukempff
jukempff

Reputation: 965

React.DOM.input is not a ReactElement, but a React class.

To simply fix your Warning/Error message, you would have to change

propTypes:
    comp: React.PropTypes.element

to

propTypes:
comp: React.PropTypes.func

since typeof React.DOM.input is a class, aka. function.

To create a React.PropTypes.element you would have to call React.DOM.input.

Upvotes: 3

Related Questions