Create React-Native Apps with CoffeeScript

“Create React-Native Apps with CoffeeScript”  #javascript #Mobileapps

  • I installed cjsx and compiled my code again: ( see the compiled result )
  • cjsx supports the same options as the CoffeeScript compiler.
  • Never miss a story from , when you sign up for Medium.
  • The plain CoffeeScript compiler can’t understand JSX, but cjsx can help !
  • To avoid calling the command on every code change just add the -w option and it watches for file changes.

Being a web developer I really like React-Native to create native apps, while leveraging my existing Javascript knowledge.
More…

@techjunkiejh: “Create React-Native Apps with CoffeeScript” #javascript #Mobileapps

Being a web developer I really like React-Native to create native apps, while leveraging my existing Javascript knowledge. 

More importantly one can actually use the same code for Android and iOS!

However I am a big fan of using CoffeeScript over Javascript for its nice syntax. So I thought why not just write it in CoffeeScript:

render: ->

React.createElement Text, style: styles.heading, “Hello World”

heading:

fontSize: 42

textAlign: ‘center’

marginTop: 50

Now compile it to JS and run the app:

But I want JSX!

Using React.createElement for everything isn’t that nice. The plain CoffeeScript compiler can’t understand JSX, but cjsx can help here!

So I changed my code to use JSX:

render: -> Hello World

heading:

fontSize: 42

textAlign: ‘center’

marginTop: 50

I installed cjsx and compiled my code again: (see the compiled result)

Et voilà it compiles and runs!

cjsx supports the same options as the CoffeeScript compiler. To avoid calling the command on every code change just add the -w option and it watches for file changes.

If you want to use a build tool instead, there are also plugins for gulp and grunt.

Create React-Native Apps with CoffeeScript