react-rails icon indicating copy to clipboard operation
react-rails copied to clipboard

type.toUpperCase error

Open eyaleizenberg opened this issue 11 years ago • 7 comments

Hi, I have the following code:

UserViewComponent = React.createBackboneClass(
  changeOptions: "change:name"
  render: ->
    `<h2>{this.getModel().get("name")}</h2>`
)

user = new Backbone.Model(name: "Eyal")
UserView = React.createFactory(UserViewComponent)
userView = UserView(model: user)

do ($ = jQuery) ->
  $ ->
    React.render(userView, $('#zibi')[0])

This works fine. If I want to use the helper method:

react_component('userView')

I am hit with:

Uncaught TypeError: type.toUpperCase is not a functionautoGenerateWrapperClass @ react_components.js:9260getComponentClassForElement @ react_components.js:13202validatePropTypes @ react_components.js:10503ReactElementValidator.createElement @ react_components.js:10550window.ReactRailsUJS.mountComponents @ react_components.js:19647(anonymous function) @ react_components.js:19694jQuery.Callbacks.fire @ application.js:3075jQuery.Callbacks.self.fireWith @ application.js:3187jQuery.extend.ready @ application.js:434completed @ application.js:105

(I naturally first change the userView variable to be @userVariable)

Any ideas?

Thanks

eyaleizenberg avatar May 26 '15 15:05 eyaleizenberg

A few thoughts:

  • react_component expects a component class, not an instance. In your case, this might be:

      react_component("UserView", userName:  "Eyal")
    

    (The second argument is props to instantiate the class)

  • .coffee files are wrapped in an anonymous function, so by default, variables defined in a .coffee file can't be accessed outside that file. Overcome this by attaching your component class to the window object (or @, in coffeescript):

      @UserView = React.createFactory(...)
    
  • BTW, that type.toUpperCase ... error is thrown when it can't find a component class with the given name. Usually it's either a typo in one of the names or a missing class.

Does any of that help?

rmosolgo avatar May 27 '15 04:05 rmosolgo

Had the type.toUpperCase error and turns out I had forgot a module.exports at the end of my jsx file. So helped me at least - so thanks (:

talmobi avatar Jun 21 '15 18:06 talmobi

hope those suggestions helped!

rmosolgo avatar Jun 30 '15 04:06 rmosolgo

@talmobi ha. that was my exact issue. Such a stupid, simple oversight!

hellatan avatar Aug 31 '15 21:08 hellatan

Hm, I have the same error. Odd. Just installed react-rails and generated a component using the generator. So I shouldn't have to modify anything? Any advice?

ncri avatar Sep 21 '15 12:09 ncri

Okay, was a name clash. I had already a variable named the same as my component. Would be really helpful to have a better error here... ;-) Took me a while to figure it out.

ncri avatar Sep 21 '15 13:09 ncri

lol @ncri the same happened to me! Thanks for posting that, otherwise I'd take a few years to discover.

Ricardonacif avatar Feb 08 '16 21:02 Ricardonacif