beta1 blog entry: Fix CoffeeScript example
Fix the constructor call and make code more idiomatic.
Wout Mertens committed
Feb 25, 2015 at 18:46 UTC
ce7190537ff50bc544e2fb246f7c4eb0f00e228b
1 file changed
+11
-8
docs/_posts/2015-01-27-react-v0.13.0-beta-1.md
+11
-8
@@ -135,17 +135,20 @@ You can also use CoffeeScript classes:
135
div = React.createFactory 'div'
136
137
class Counter extends React.Component
138
- @propTypes =
139
- initialCount: React.PropTypes.number
140
- @defaultProps =
141
- initialCount: 0
142
- constructor: ->
143
- @state =
144
- count: @props.initialCount
138
+ @propTypes = initialCount: React.PropTypes.number
139
+ @defaultProps = initialCount: 0
140
+
141
+ constructor: (props) ->
142
+ super props
143
+ @state = count: props.initialCount
144
+
145
tick: =>
146
@setState count: @state.count + 1
147
+
148
render: ->
148
- div(onClick: @tick, 'Clicks: ', @state.count)
149
+ div onClick: @tick,
150
+ 'Clicks: '
151
+ @state.count
152
```
153
154
You can even use the old ES3 module pattern if you want: