Last active
May 11, 2016 19:41
-
-
Save FreekingDean/8be14215bb6bfcbc905bd6d6efc7fbf7 to your computer and use it in GitHub Desktop.
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
import React from 'react'; | |
class App extends React.Component { | |
constructor(){ | |
super(); | |
this.state = {expression: '0', runningTotal: 0 } | |
} | |
shouldComponentUpdate(nextProps) { | |
//YOUR CODE GOES HERE | |
return true; | |
} | |
update(strExpression){ | |
this.setState({expression: strExpression.target.value}); | |
try { | |
this.setState({runningTotal: eval(strExpression.target.value), error: undefined}); | |
} catch(err) { | |
this.setState({error: err}); | |
//ignore | |
} | |
} | |
render(){ | |
return ( | |
<div> | |
<input type="text" onKeyUp = {this.update.bind(this)} /> | |
<h1>{this.state.expression}={this.state.runningTotal}</h1> | |
</div> | |
); | |
} | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment