728x90
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script crossorigin src="https://unpkg.com/react@17/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
class Counter extends React.Component{
state = {
number:0
}
incre = (index)=>{
const increase = {
...this.state,
number:this.state.number + index
}
this.setState(increase)
}
decre = (index)=>{
const decrease = {
...this.state,
number:this.state.number -index
}
this.setState(decrease)
}
render(){
return(
<div>
<h3>{this.state.number}</h3>
<button onClick={ ()=>{ this.incre(2)} }>+</button>
<button onClick={ ()=>{ this.decre(2)}}>-</button>
</div>
)
}
}
class App extends React.Component{
render(){
return(
<div>
<Counter/>
</div>
)
}
}
ReactDOM.render(
<App/>,
document.querySelector('#root')
)
</script>
</body>
</html>
728x90
'프론트엔드 > React' 카테고리의 다른 글
[React]틱택토게임 만들기 (0) | 2022.04.14 |
---|---|
[React] 타자 입력 시마다 value값 변하는 form만들기 (0) | 2022.04.14 |
[React] 버튼 클릭할 때마다 버튼 글씨 바꾸기 (0) | 2022.04.13 |
[React] props, state에 대해서 알아보자.(예시 코드 有) (0) | 2022.04.13 |
[React]리액트(React)란? 리액트 기본 개념 (0) | 2022.04.13 |