Skip to content

Instantly share code, notes, and snippets.

@dai-shi
Created March 27, 2016 12:46
Show Gist options
  • Select an option

  • Save dai-shi/909bac9950f1449af5ca to your computer and use it in GitHub Desktop.

Select an option

Save dai-shi/909bac9950f1449af5ca to your computer and use it in GitHub Desktop.
diff --git a/imports/ui/App.jsx b/imports/ui/App.jsx
index c452da9..332bd6e 100644
--- a/imports/ui/App.jsx
+++ b/imports/ui/App.jsx
@@ -1,4 +1,5 @@
import React, { Component, PropTypes } from 'react';
+import ReactDOM from 'react-dom';
import { createContainer } from 'meteor/react-meteor-data';
import { Tasks } from '../api/tasks.js';
@@ -7,6 +8,21 @@ import Task from './Task.jsx';
// App component - represents the whole app
class App extends Component {
+ handleSubmit(event) {
+ event.preventDefault();
+
+ // Find the text field via the React ref
+ const text = ReactDOM.findDOMNode(this.refs.textInput).value.trim();
+
+ Tasks.insert({
+ text,
+ createdAt: new Date(), // current time
+ });
+
+ // Clear form
+ ReactDOM.findDOMNode(this.refs.textInput).value = '';
+ }
+
renderTasks() {
return this.props.tasks.map((task) => (
<Task key={task._id} task={task} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment