Last active
October 28, 2018 05:06
-
-
Save gujc71/f2d052aea931610ca05fc1c7396ab25f 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
import React, { Component } from 'react'; | |
class BoardForm extends Component { | |
shouldComponentUpdate(nextProps, nextState) { | |
let selectedBoard = nextProps.selectedBoard; | |
if (!selectedBoard.brdno) { | |
this.brdtitle.value = ""; | |
this.brdwriter.value = ""; | |
return true; | |
} | |
this.brdtitle.value = selectedBoard.brdtitle; | |
this.brdwriter.value = selectedBoard.brdwriter; | |
return true; | |
} | |
handleSubmit = (e) => { | |
e.preventDefault(); | |
let selectedBoard = this.props.selectedBoard; | |
let data = { | |
brdwriter: this.brdwriter.value, | |
brdtitle: this.brdtitle.value | |
} | |
if (selectedBoard.brdno) { | |
data.brdno = selectedBoard.brdno | |
data.brddate = selectedBoard.brddate | |
} | |
this.props.onSaveData(data); | |
} | |
render() { | |
return ( | |
<form onSubmit={this.handleSubmit}> | |
<input placeholder="title" ref={node => this.brdtitle = node}/> | |
<input placeholder="name" ref={node => this.brdwriter = node}/> | |
<button type="submit">Save</button> | |
</form> | |
); | |
} | |
} | |
export default BoardForm; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment