Skip to content

Instantly share code, notes, and snippets.

@pratik-chakravorty
Last active March 29, 2018 04:23
Show Gist options
  • Save pratik-chakravorty/3550546a562131a06c29f976a80fb19d to your computer and use it in GitHub Desktop.
Save pratik-chakravorty/3550546a562131a06c29f976a80fb19d to your computer and use it in GitHub Desktop.
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