forked from njsh4261/swpp-react-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathNewTodo.js
More file actions
36 lines (35 loc) · 1.22 KB
/
Copy pathNewTodo.js
File metadata and controls
36 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React, { Component } from 'react';
import '../NewTodo.css';
import { Redirect } from 'react-router-dom';
class NewTodo extends Component {
state = {
title: '',
content: '',
submitted: false,
}
render() {
if (this.state.submitted) {
return <Redirect to='/todos' />
}
return (
<div className="NewTodo">
<h1>Add a Todo</h1>
<label>Title</label>
<input type="text" value={this.state.title}
onChange={(event) => this.setState({ title: event.target.value })} />
<label>Content</label>
<textarea rows="4" type="text" value={this.state.content}
onChange={(event) => this.setState({ content: event.target.value })} />
<button onClick={() => this.postTodoHandler()}>Submit</button>
</div>
);
}
postTodoHandler = () => {
const data =
{ title: this.state.title, content: this.state.content };
alert('Submitted\n' + data.title + '\n' + data.content);
this.setState( {submitted: true} );
this.props.history.push('/todos');
}
};
export default NewTodo;