Skip to content

Instantly share code, notes, and snippets.

@FreekingDean
Last active May 11, 2016 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FreekingDean/8be14215bb6bfcbc905bd6d6efc7fbf7 to your computer and use it in GitHub Desktop.
Save FreekingDean/8be14215bb6bfcbc905bd6d6efc7fbf7 to your computer and use it in GitHub Desktop.
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