Last active
October 27, 2018 23:11
-
-
Save gujc71/d4399afeff639920d7960afa2d05fe7f to your computer and use it in GitHub Desktop.
react_board
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
state = { | |
maxNo: 3, | |
boards: [ ~~ 생략 ~~ | |
} | |
handleSaveData = (data) => { | |
this.setState({ | |
boards: this.state.boards.concat({ brdno: this.state.maxNo++, brddate: new Date(), ...data }) | |
}); | |
} | |
render() { | |
const { boards } = this.state; | |
return ( | |
<div> | |
<BoardForm onSaveData={this.handleSaveData}/> | |
<table border="1"> | |
<tbody> | |
~~ 생략 ~~ | |
} | |
class BoardForm extends Component { | |
state = {} | |
handleChange = (e) => { | |
this.setState({ | |
[e.target.name]: e.target.value | |
}) | |
} | |
handleSubmit = (e) => { | |
e.preventDefault(); | |
this.props.onSaveData(this.state); | |
this.setState({}); | |
} | |
render() { | |
return ( | |
<form onSubmit={this.handleSubmit}> | |
<input placeholder="title" name="brdtitle" onChange={this.handleChange}/> | |
<input placeholder="name" name="brdwriter" onChange={this.handleChange}/> | |
<button type="submit">Save</button> | |
</form> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment