Last active
December 18, 2016 13:36
-
-
Save some1else/e6f39691f7345d35b66bbfa52bec6853 to your computer and use it in GitHub Desktop.
Using Class.prototype.state for default initial state.
This file contains 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
class App extends React.Component { | |
startWondering = (e) => { | |
this.setState({ feeling: 'wondering' }) | |
} | |
render() { | |
const { feeling } = this.state | |
const { feeling: initialFeeling } = this.__proto__.state | |
if (feeling != initialFeeling) { | |
return <p>I am now { feeling }. Usually I am { initialFeeling }.</p> | |
} else { | |
return <p onClick={ this.startWondering }>I think I am always { feeling }.</p> | |
} | |
} | |
} | |
// Are we missing an idiomatic way to do this inside the class definition? | |
App.prototype.state = { feeling: "fine with it" } | |
React.render(<App />, document.getElementById('app')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment