-
Notifications
You must be signed in to change notification settings - Fork 6
React
Shane Brinkman-Davis Delamore edited this page May 6, 2017
·
16 revisions
CaffeineScript is ideal for React-style programming.
import &react, &reactdom, &ArtStandardLib.createObjectTreeFactories
[] :div
React.createElement
class Timer extends Component
constructor: ->
@state = secondsElapsed: 0
tick: ->
@setState (prevState) ->
secondsElapsed: prevState.secondsElapsed + 1
componentDidMount: ->
@interval = setInterval
-> @tick()
1000
componentWillUnmount: ->
clearInterval @interval
render: ->
Div "" Seconds Elapsed: #{@state.secondsElapsed}
render Timer, mountNode
class Timer extends React.Component {
constructor(props) {
super(props);
this.state = {secondsElapsed: 0};
}
tick() {
this.setState((prevState) => ({
secondsElapsed: prevState.secondsElapsed + 1
}));
}
componentDidMount() {
this.interval = setInterval(() => this.tick(), 1000);
}
componentWillUnmount() {
clearInterval(this.interval);
}
render() {
return (
<div>Seconds Elapsed: {this.state.secondsElapsed}</div>
);
}
}
ReactDOM.render(<Timer />, mountNode);
- Home
- Get Started
- Benefits
- Highlights
- Productivity by Design
- CaffeineScript Design
- What is CaffeineScript Good For?
- Get the most out of JavaScript
- Language Comparison
- CHANGELOG
- Blocks Instead of Brackets
- Binary Line-Starts
- Everything Returns a Value
- Streamlined Modules
- Scopes and Variables
- Optional Commas
- Semantics
- Ambiguities