Last active
August 29, 2015 14:20
-
-
Save jsdf/d386cd926ff77eef0f42 to your computer and use it in GitHub Desktop.
Run CJSX script tags in the browser
This file contains hidden or 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
<!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