Browse Source

one liner

main
Jared Forsyth 11 years ago
parent
commit
ba50af55f7
  1. 6
      tips/10-props-in-getInitialState-as-anti-pattern.md

6
tips/10-props-in-getInitialState-as-anti-pattern.md

@ -68,14 +68,12 @@ However, it's **not** an anti-pattern if you intentionally make it clear that sy
var Counter = React.createClass({ var Counter = React.createClass({
getInitialState: function() { getInitialState: function() {
// naming it initialX clearly indicates that the only purpose // naming it initialX clearly indicates that the only purpose
// of the passed down prop is to initialize something internal // of the passed down prop is to initialize something internal
return {count: this.props.initialCount}; return {count: this.props.initialCount};
}, },
handleClick: function() { handleClick: function() {
this.setState({ this.setState({count: this.state.count + 1});
count: this.state.count + 1
});
}, },
render: function() { render: function() {
return <div onClick={this.handleClick}>{this.state.count}</div>; return <div onClick={this.handleClick}>{this.state.count}</div>;

Loading…
Cancel
Save