Created
June 3, 2014 03:53
-
-
Save ajorgensen/daba080a250ad7b27cf6 to your computer and use it in GitHub Desktop.
Simple example of react and coffeescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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