{"size": 1402, "ext": "js", "max_stars_repo_path": "src/components/addPost.js", "max_stars_repo_name": "Tocico/my-first-gatsby-app", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/addPost.js", "max_issues_repo_name": "Tocico/my-first-gatsby-app", "max_issues_repo_issues_event_min_datetime": "2021-05-10T09:56:06.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-18T08:29:40.000Z", "max_forks_repo_path": "src/components/addPost.js", "max_forks_repo_name": "Tocico/my-first-gatsby-app", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 5, "max_forks_count": null, "avg_line_length": 29.829787234, "max_line_length": 122, "alphanum_fraction": 0.4450784593}
import React from "react"


export default class addPost extends React.Component {
    state = {
        title: '',
        date: '',
        content: ''
    }
    handleChange=(e)=>{
         const today = new Date();
         const date = today.getFullYear() + "-" +  (today.getMonth()+1)  + "-"+ today.getDate();
        console.log(date);
         this.setState({
             [e.target.id]: e.target.value,
             date: date
            });
    }
    handleSubmit=(e)=>{
        e.preventDefault();
        this.props.addPost(this.state);
        this.setState({
            title: '',
            content: ''
        })
    }
    render() {
        return (
            <div className="addpost-form">
                <form onSubmit={this.handleSubmit}>
                    <div>
                    <label htmlFor="title">Title</label>
                    <input type="text" onChange={this.handleChange} id="title" value={this.state.title}></input>
                    </div>
                    <div>
                    <label htmlFor="content">Content</label>
                    <textarea type="text" onChange={this.handleChange} id="content" value={this.state.content}></textarea>
                    </div>
                    <div>
                    <button className="post-btn">Post</button>
                    </div>
                </form>
            </div>
        )
    }
}
