type.toUpperCase error
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
A few thoughts:
-
react_componentexpects 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)
-
.coffeefiles are wrapped in an anonymous function, so by default, variables defined in a.coffeefile can't be accessed outside that file. Overcome this by attaching your component class to thewindowobject (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?
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 (:
hope those suggestions helped!
@talmobi ha. that was my exact issue. Such a stupid, simple oversight!
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?
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.
lol @ncri the same happened to me! Thanks for posting that, otherwise I'd take a few years to discover.