Created
November 3, 2018 12:16
-
-
Save gujc71/d5ee6eaaab5cbf677257f3fa19212ae3 to your computer and use it in GitHub Desktop.
redux_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'; | |
import { connect } from 'react-redux'; | |
import { board_save } from './App_reducer' | |
class BoardForm extends Component { | |
state = {}; | |
initialSelectedBoard = { | |
brdno: "", | |
brdtitle: "", | |
brdwriter: "", | |
brddate: "" | |
}; | |
handleChange = (e) => { | |
this.setState ({[e.target.name]: e.target.value}); | |
} | |
handleSave = () => { | |
this.props.dispatch(board_save(this.state)); | |
this.setState (this.initialSelectedBoard); | |
} | |
componentWillReceiveProps(nextProps) { | |
this.setState (nextProps.selectedBoard); | |
} | |
render() { | |
return ( | |
<div> | |
<input placeholder="title" name="brdtitle" value={this.state.brdtitle} onChange={this.handleChange} /> | |
<input placeholder="name" name="brdwriter" value={this.state.brdwriter} onChange={this.handleChange} /> | |
<button onClick={this.handleSave}>Save</button> | |
</div> | |
); | |
} | |
} | |
let mapStateToProps = (state) => { | |
return { | |
selectedBoard: state.selectedBoard | |
}; | |
} | |
export default connect(mapStateToProps)(BoardForm); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment