From ce7190537ff50bc544e2fb246f7c4eb0f00e228b Mon Sep 17 00:00:00 2001 From: Wout Mertens Date: Wed, 25 Feb 2015 18:46:32 +0100 Subject: [PATCH] beta1 blog entry: Fix CoffeeScript example Fix the constructor call and make code more idiomatic. --- .../_posts/2015-01-27-react-v0.13.0-beta-1.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/_posts/2015-01-27-react-v0.13.0-beta-1.md b/docs/_posts/2015-01-27-react-v0.13.0-beta-1.md index fafb5cfbec..22f2079dd9 100644 --- a/docs/_posts/2015-01-27-react-v0.13.0-beta-1.md +++ b/docs/_posts/2015-01-27-react-v0.13.0-beta-1.md @@ -135,17 +135,20 @@ You can also use CoffeeScript classes: div = React.createFactory 'div' class Counter extends React.Component - @propTypes = - initialCount: React.PropTypes.number - @defaultProps = - initialCount: 0 - constructor: -> - @state = - count: @props.initialCount + @propTypes = initialCount: React.PropTypes.number + @defaultProps = initialCount: 0 + + constructor: (props) -> + super props + @state = count: props.initialCount + tick: => @setState count: @state.count + 1 + render: -> - div(onClick: @tick, 'Clicks: ', @state.count) + div onClick: @tick, + 'Clicks: ' + @state.count ``` You can even use the old ES3 module pattern if you want: