Last active
January 23, 2017 04:20
-
-
Save Gethyl/66177143634656876263d9500ab52195 to your computer and use it in GitHub Desktop.
The Main and Calculator component used to explain Virtual DOM
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" | |
import ReactDOM from "react-dom" | |
export default class Calculator extends React.Component{ | |
constructor(props) { | |
super(props); | |
this.state = {output: ""}; | |
} | |
render(){ | |
let IntegerA,IntegerB,IntegerC; | |
return( | |
<div className="container"> | |
<h2>using React</h2> | |
<div>Input 1: | |
<input type="text" placeholder="Input 1" ref="input1"></input> | |
</div> | |
<div>Input 2 : | |
<input type="text" placeholder="Input 2" ref="input2"></input> | |
</div> | |
<div> | |
<button id="add" onClick={ () => { | |
IntegerA = parseInt(ReactDOM.findDOMNode(this.refs.input1).value) | |
IntegerB = parseInt(ReactDOM.findDOMNode(this.refs.input2).value) | |
IntegerC = IntegerA+IntegerB | |
this.setState({output:IntegerC}) | |
} | |
}>Add</button> | |
<button id="subtract" onClick={ () => { | |
IntegerA = parseInt(ReactDOM.findDOMNode(this.refs.input1).value) | |
IntegerB = parseInt(ReactDOM.findDOMNode(this.refs.input2).value) | |
IntegerC = IntegerA-IntegerB | |
this.setState({output:IntegerC}) | |
} | |
}>Subtract</button> | |
</div> | |
<div> | |
<hr/> | |
<h2>Output: {this.state.output}</h2> | |
</div> | |
</div> | |
); | |
} | |
} |
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"; | |
import Calculator from "./Calculator" | |
export default class Layout extends React.Component{ | |
render(){ | |
return( | |
<div> | |
<h1>Basic Calculator</h1> | |
<Calculator/> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment