Last active
March 29, 2018 04:23
-
-
Save pratik-chakravorty/3550546a562131a06c29f976a80fb19d to your computer and use it in GitHub Desktop.
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'; | |
class EditComponent extends Component { | |
handleEdit = (e) => { | |
e.preventDefault(); | |
const newTitle = this.getTitle.value; | |
const newMessage = this.getMessage.value; | |
const data = { | |
newTitle, | |
newMessage | |
} | |
this.props.dispatch({ type: 'UPDATE', id: this.props.post.id, data: data }) | |
} | |
render() { | |
return ( | |
<div key={this.props.post.id} className="post"> | |
<form className="form" onSubmit={this.handleEdit}> | |
<input required type="text" ref={(input) => this.getTitle = input} | |
defaultValue={this.props.post.title} placeholder="Enter Post Title" /><br /><br /> | |
<textarea required rows="5" ref={(input) => this.getMessage = input} | |
defaultValue={this.props.post.message} cols="28" placeholder="Enter Post" /><br /><br /> | |
<button>Update</button> | |
</form> | |
</div> | |
); | |
} | |
} | |
export default connect()(EditComponent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment