meteor / react-tutorial

React Tutorial is the best place to learn how to use React and Meteor together
https://react-tutorial.meteor.com/
39 stars 87 forks source link

doc(methods): update wrong imports to update #53

Closed vit0rr closed 1 year ago

vit0rr commented 1 year ago

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 image

Grubba27 commented 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>
  );
};
vit0rr commented 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>
  );
};

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