Skip to content

Commit

Permalink
3.1. class 스타일에서 state 사용법
Browse files Browse the repository at this point in the history
  • Loading branch information
egoing committed Feb 11, 2020
1 parent 7e2101c commit 9864eda
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/App.js
Expand Up @@ -5,25 +5,35 @@ function App() {
return (
<div className="container">
<h1>Hello World</h1>
<FuncComp></FuncComp>
<ClassComp></ClassComp>
<FuncComp initNumber={2}></FuncComp>
<ClassComp initNumber={2}></ClassComp>
</div>
);
}

function FuncComp(){
function FuncComp(props){
return (
<div className="container">
<h2>function style component</h2>
<p>Number : {props.initNumber}</p>
</div>
);
}

class ClassComp extends React.Component{
state = {
number:this.props.initNumber
}
render(){
return (
<div className="container">
<h2>class style component</h2>
<p>Number : {this.state.number}</p>
<input type="button" value="random" onClick={
function(){
this.setState({number:Math.random()})
}.bind(this)
}></input>
</div>
)
}
Expand Down

0 comments on commit 9864eda

Please sign in to comment.