Created
July 2, 2018 14:44
-
-
Save niinpatel/d18cfc7864f0f6d6bb38c4b6da609bcc to your computer and use it in GitHub Desktop.
This file contains hidden or 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, { Component } from 'react'; | |
import './App.css'; | |
import ResultComponent from './components/ResultComponent'; | |
import KeyPadComponent from "./components/KeyPadComponent"; | |
class App extends Component { | |
constructor(){ | |
super(); | |
this.state = { | |
result: "" | |
} | |
} | |
calculate = () => { | |
try { | |
this.setState({ | |
// eslint-disable-next-line | |
result: (eval(this.state.result) || "" ) + "" | |
}) | |
} catch (e) { | |
this.setState({ | |
result: "error" | |
}) | |
} | |
}; | |
reset = () => { | |
this.setState({ | |
result: "" | |
}) | |
}; | |
backspace = () => { | |
this.setState({ | |
result: this.state.result.slice(0, -1) | |
}) | |
}; | |
render() { | |
return ( | |
<div> | |
<div className="calculator-body"> | |
<h1>Simple Calculator</h1> | |
<ResultComponent result={this.state.result}/> | |
<KeyPadComponent onClick={this.onClick}/> | |
</div> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment