Created
September 13, 2018 15:37
-
-
Save khunemz/65977720808a0fb02e5f2dbda33eae2b to your computer and use it in GitHub Desktop.
learn_react_1_by_khunemz
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
// Write JavaScript here and press Ctrl+Enter to execute | |
// React, ReactDOM | |
class Button extends React.Component { | |
// constructor(props) { | |
// super(props); | |
// this.state = { cnt: 0 }; | |
// } | |
handleClick = function () { | |
// this === component instance | |
this.props.conClickFunction(this.props.incrementValue); | |
}; | |
render() { | |
return <button onClick="{this.handleClick}"> | |
+{this.props.incrementValue}</button> | |
} | |
} | |
const Result = (props) => { | |
return ( | |
<div>{props.cnt}</div> | |
); | |
} | |
class App extends React.Component { | |
state = { cnt: 0 }; | |
incrementcnt = function() { | |
this.setState({ | |
function (prevState) { | |
cnt: prevState.cnt + incrementValue; | |
} | |
}); | |
}; | |
render() { | |
return ( | |
<div> | |
<Button incrementValue={1} onClickFunction="{this.incrementcnt}" /> | |
<Button incrementValue={2} onClickFunction="{this.incrementcnt}" /> | |
<Button incrementValue={5} onClickFunction="{this.incrementcnt}" /> | |
<Result cnt={this.state.cnt} /> | |
</div> | |
); | |
} | |
} | |
ReactDOM.render(<App /> , mountNode); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment