Skip to content

Instantly share code, notes, and snippets.

@pratik-chakravorty
Last active March 29, 2018 04:18
Show Gist options
  • Save pratik-chakravorty/960161418be48790814761b75935a9ca to your computer and use it in GitHub Desktop.
Save pratik-chakravorty/960161418be48790814761b75935a9ca to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import { connect } from 'react-redux';
class PostForm extends Component {
handleSubmit = (e) => {
e.preventDefault();
const title = this.getTitle.value;
const message = this.getMessage.value;
const data = {
id: new Date(),
title,
message,
editing: false
}
this.props.dispatch({
type: 'ADD_POST',
data
})
this.getTitle.value = '';
this.getMessage.value = '';
}
render() {
return (
<div className="post-container">
<h1 className="post_heading">Create Post</h1>
<form className="form" onSubmit={this.handleSubmit} >
<input required type="text" ref={(input) => this.getTitle = input}
placeholder="Enter Post Title" /><br /><br />
<textarea required rows="5" ref={(input) => this.getMessage = input}
cols="28" placeholder="Enter Post" /><br /><br />
<button>Post</button>
</form>
</div>
);
}
}
export default connect()(PostForm);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment