Skip to content

Instantly share code, notes, and snippets.

@wmertens
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wmertens/4aeb05dfffd77db57351 to your computer and use it in GitHub Desktop.
Save wmertens/4aeb05dfffd77db57351 to your computer and use it in GitHub Desktop.
PwRggP
# Pure coffeescript React.JS
# Also features "global state manager"
R = React.DOM
N = null
# global state manager
render = null
state = clicks: 0
count = ->
state.clicks++
render()
Hello = React.createClass
shouldComponentUpdate: (props) ->
props.clicks isnt @props.clicks
componentDidMount: ->
console.log "new element"
count: ->
count()
render: ->
R.div N, "Hello #{@props.name}",
R.p N, "How are you?"
R.button onClick: @count, "Click me"
R.p N, """
Clicked #{@props.clicks} time#{if @props.clicks != 1 then "s" else ""}.
"""
render = ->
React.renderComponent Hello(name:"World", clicks:state.clicks), document.body
render()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment