N
N
Nick V2015-10-25 16:16:44
Node.js
Nick V, 2015-10-25 16:16:44

How to write MeteorJS and ReactJS in CoffeeScript?

Good day everyone. I started learning meteorjs and reactjs and got this problem. I can’t enter how to write react in coffeescript in meteor. Please throw guides or tutorials or explain how it's done.
The sequence of my actions:

  • $ meteor create app
  • cd app
  • meteor remove autopublish insecure
  • meteor add coffeescript stylus mquandalle:jade react jhartma:cjsx

Next, following this instruction, I create a file:
hello.jade
head
  title Todo List
body
  #render-target


and file
hello.cjsx
if Meteor.isClient
  Meteor.startup ->
    App = React.createClass
      displayName: 'App'
      render: ->
        <div>Hi?</div>
    React.render <App />, document.getElementById 'render-target'


If you do so, then the template is rendered. If you move the created component to a separate file, it gives an error
Uncaught ReferenceError: App is not defined
hello.cjsx
if Meteor.isClient
    React.render <App />, document.getElementById 'render-target'

app.cjsx
App = React.createClass
  displayName: 'App'
    render: ->
      <div>Hi?</div>


Help me to understand.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
Nick V, 2015-10-25
@half-life

Thanks everliving . You need to make the component global via @

M
Misha Kogan, 2015-10-25
@Kogan4ik

You need to install the package in meteor

E
everliving, 2015-10-25
@everliving

Required packages for CS:
coffeescript
jhartma:cjsx
- a small tutorial
Official package for React:
also started with CS at first, but I think ES6 is better

A
Amir Boziev, 2015-11-11
@AMRBZ

How to write it in cjsx ?

renderTasks() {
    return this.getTasks().map((task) => {
      return <Task key={task._id} task={task} />;
    });
}

Github source

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question