Skip to content

Instantly share code, notes, and snippets.

@wvmitchell
Created October 24, 2018 13:48
Show Gist options
  • Select an option

  • Save wvmitchell/af56336cb50e867b44a3ba91c873b205 to your computer and use it in GitHub Desktop.

Select an option

Save wvmitchell/af56336cb50e867b44a3ba91c873b205 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
import { connect } from 'react-redux'
import uuid from 'uuid/v1'
class AddTodoForm extends Component {
constructor(props) {
super(props)
this.state = { text: '' }
}
render() {
const { handleSubmit, todos } = this.props;
return (
<section>
<h2>Things to do: {todos.length}</h2>
<form onSubmit={ (e) => {
e.preventDefault()
handleSubmit(this.state.text, uuid())
}}>
<input value={this.state.text}
placeholder="Add A Todo"
onChange={(e) => this.setState({ text: e.target.value} )} />
<button>Add Todo</button>
</form>
</section>
)
}
}
export default AddTodoForm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment