Closed vit0rr closed 1 year ago
It should have as stated here
Your file should look like this:
import React, { useState } from 'react';
import { TasksCollection } from '/imports/api/TasksCollection';
export const TaskForm = () => {
const [text, setText] = useState("");
const handleSubmit = e => {
e.preventDefault();
if (!text) return;
TasksCollection.insert({
text: text.trim(),
createdAt: new Date()
});
setText("");
};
return (
<form className="task-form" onSubmit={handleSubmit}>
<input
type="text"
placeholder="Type to add new tasks"
value={text}
onChange={(e) => setText(e.target.value)}
/>
<button type="submit">Add Task</button>
</form>
);
};
It should have as stated here
Your file should look like this:
import React, { useState } from 'react'; import { TasksCollection } from '/imports/api/TasksCollection'; export const TaskForm = () => { const [text, setText] = useState(""); const handleSubmit = e => { e.preventDefault(); if (!text) return; TasksCollection.insert({ text: text.trim(), createdAt: new Date() }); setText(""); }; return ( <form className="task-form" onSubmit={handleSubmit}> <input type="text" placeholder="Type to add new tasks" value={text} onChange={(e) => setText(e.target.value)} /> <button type="submit">Add Task</button> </form> ); };
You are right. Probably I removed the import at the same time that I removed the TasksCollection.insert
to use methods and forgot. I'll close this PR
Hello :)
These paths to updates are wrong. To have a reference, follow the step09 file. It does not have any
TasksCollection
to update in this file.The doc: https://react-tutorial.meteor.com/simple-todos/09-methods.html#9-4-api-and-db-folders