Skip to content

Instantly share code, notes, and snippets.

@ajorgensen
Created June 3, 2014 03:53
Show Gist options
  • Save ajorgensen/daba080a250ad7b27cf6 to your computer and use it in GitHub Desktop.
Save ajorgensen/daba080a250ad7b27cf6 to your computer and use it in GitHub Desktop.
Simple example of react and coffeescript
data = [
{ first: 'Bruce', last: 'Wayne' },
{ first: 'Peter', last: 'Parker' },
{ first: 'Foo', last: 'Bar' }]
person = React.createClass
render: ->
(
(React.DOM.div {}, [
(React.DOM.h2 {}, [ "#{@props.last}, #{@props.first}" ])
])
)
personList = React.createClass
render: ->
people = @props.data.map (p) -> (person {first: p.first, last: p.last })
(React.DOM.div {}, [people])
personApp = React.createClass
render: ->
(React.DOM.div {}, [
(React.DOM.h1 {}, ['This is the app'])
(personList {data: @props.data})
])
$ ->
React.renderComponent (personApp {data: data}), document.getElementById("foo")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment