Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

(Note: I'm using the 'therubyracer', 'react-rails', and 'sprockets-coffee-react' gems)

This is the code for my simple component (Hello.js.cjsx):

# @cjsx React.DOM

Hello = React.createClass(
  render: ->
    <div>
      Hello {@props.name || "World"}!
    </div>
)

window.components ?= {}
window.components.Hello = Hello

In my rails view (index.html.erb) this works just fine:

<%= render_component('components.Hello', {name: 'Jack'}) %>

However, when I try this:

<%= react_component('components.Hello', {name: 'Jill'}, {prerender: true}) %>

I get this error:

Encountered error "ReferenceError: components is not defined"

which seems odd because I'm defining it in my component.

What am I doing wrong?

share|improve this question

This question has an open bounty worth +50 reputation from phaedryx ending in 18 hours.

This question has not received enough attention.

    
it's what it is. Undefined error. What is "?="? –  Vadim Chumel Oct 11 at 8:33
    
The ?= is coffeescript's 'existential' operator. Its javascript equivalent is: if (window.components == null) { window.components = {}; } –  phaedryx Oct 11 at 15:20
    
I should add that changing that line to: window.components = {} Doesn't fix the problem. –  phaedryx Oct 11 at 15:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.