Skip to content

Instantly share code, notes, and snippets.

@jsdf
Last active August 29, 2015 14:20
Show Gist options
  • Save jsdf/d386cd926ff77eef0f42 to your computer and use it in GitHub Desktop.
Save jsdf/d386cd926ff77eef0f42 to your computer and use it in GitHub Desktop.
Run CJSX script tags in the browser
<!DOCTYPE html>
<html>
<head>
<title>CJSX in a script tag</title>
<script src="https://fb.me/react-0.13.2.js"></script>
<script type="text/javascript" src="https://wzrd.in/standalone/coffee-react-browser"></script>
<script type="text/cjsx">
# defining a component
class Clock extends React.Component
@defaultProps = interval: 2000
constructor: (props) ->
super props
@state = time: new Date
componentDidMount: ->
setInterval(@tick, @props.interval)
tick: =>
@setState time: new Date
render: ->
<h1>{@state.time.toLocaleTimeString()}</h1>
# rendering to the page
React.render(<Clock interval={100} />, document.body)
# that's all folks :D
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment