Skip to content

Instantly share code, notes, and snippets.

@iosdev-republicofapps
Created September 4, 2017 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iosdev-republicofapps/b08c74628f631b3fcaa3afc6681511de to your computer and use it in GitHub Desktop.
Save iosdev-republicofapps/b08c74628f631b3fcaa3afc6681511de to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import './App.css';
import TodoListItemCreator from './TodoListItemCreator';
class App extends Component {
handleCreateItem(item) {
console.log('create item' + item);
}
render() {
return (
<div className="App">
<TodoListItemCreator onCreateItem={this.handleCreateItem} />
</div>
);
}
}
export default App;
import React, { Component } from 'react';
import PropTypes from 'prop-types';
class TodoListItemCreator extends Component {
constructor(props, context) {
super(props, context);
this.state = {
value: '',
};
this.handleSubmit = this.handleSubmit.bind(this);
this.handleChange = this.handleChange.bind(this);
}
handleSubmit(e) {
console.log("submit!");
e.preventDefault();
this.props.onCreateItem('foo')
}
handleChange(e) {
this.setState({value: e.target.value});
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<label>
Todo Item:
<input type="text" value={this.state.value} onChange={this.handleChange} />
</label>
<input type="submit" value="Add Item" />
</form>
);
}
}
TodoListItemCreator.propTypes = {
onCreateItem: PropTypes.func.isRequired,
};
export default TodoListItemCreator;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment