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 App extends React.Component{
render(){
return(
<div>
</div>
)
}
}
ReactDOM.render(
<App />,
document.querySelector('#root')
)
</script>
</body>
</html>
<div id="root"></div>
<script type="text/babel">
class Form extends React.Component{
handleChange = e => {
const {target:{value}} = e
this.props.change(value)
}
handleSubmit = e => {
e.preventDefault()
}
render(){
const {
props:{
value
},
handleChange,
handleSubmit
} = this
return(
<form onSubmit={handleSubmit}>
내용 : <input type="text" value={value} onChange={handleChange} />
<input type="submit" value="확인" />
</form>
)
}
}
class Value extends React.Component{
render(){
return(
<h3>{this.props.value}</h3>
)
}
}
// React Devloper Tool
class App extends React.Component{
state = {
value:''
}
changeValue = v => {
this.setState({
...this.state,
value:v
})
}
render(){
return(
<div>
<Form change={this.changeValue} value={this.state.value}/>
<Value value={this.state.value} />
</div>
)
}
}
ReactDOM.render(
<App />,
document.querySelector('#root')
)
</script>
</body>
728x90
'프론트엔드 > React' 카테고리의 다른 글
[React] 틱택토게임(2) 승자정하기 (0) | 2022.04.15 |
---|---|
[React]틱택토게임 만들기 (0) | 2022.04.14 |
[React] 버튼 누를 때마다 숫자 증가, 감소하는 카운터 만들기 (0) | 2022.04.13 |
[React] 버튼 클릭할 때마다 버튼 글씨 바꾸기 (0) | 2022.04.13 |
[React] props, state에 대해서 알아보자.(예시 코드 有) (0) | 2022.04.13 |