Application error in part 2 of the Meteor React.js tutorial

My app crashes (below) in the Meteor React.js tutorial . It seems that I can not find the problem, and the code is from the textbook. Help!

Desktop/simple-todos-react/.meteor/local/build/programs/server/app/simple-todos-react.js:14
    React.render(<App />, document.getElementById("render-target"));   // 6
                 ^
SyntaxError: Unexpected token <
    at Desktop/simple-todos-react/.meteor/local/build/programs/server/boot.js:241:30
    at Array.forEach (native)
    at Function._.each._.forEach (/.meteor/packages/meteor-tool/.1.1.9.1u3q681++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
    at /Desktop/simple-todos-react/.meteor/local/build/programs/server/boot.js:137:5
Exited with code: 8
Your application is crashing. Waiting for file change.

simple todos-react.html

<head>
  <title>Todo List</title>
</head>

<body>
  <div id="render-target"></div>
</body>

simple todos-react.js

if (Meteor.isClient) {
  // This code is executed on the client only

  Meteor.startup(function () {
    // Use Meteor.startup to render the component after the page is ready
    React.render(<App />, document.getElementById("render-target"));
  });
}

App.jsx

// App component - represents the whole app
App = React.createClass({
  getTasks() {
    return [
      { _id: 1, text: "This is task 1" },
      { _id: 2, text: "This is task 2" },
      { _id: 3, text: "This is task 3" },
      { _id: 4, text: "This is task 4" },
      { _id: 5, text: "This is task 5" }
    ];
  },

  renderTasks() {
    return this.getTasks().map((task) => {
      return <Task key={task._id} task={task} />;
    });
  },

  render() {
    return (
      <div className="container">
        <header>
          <h1>Todo List</h1>
        </header>

        <ul>
          {this.renderTasks()}
        </ul>
      </div>
    );
  }
});

Task.jsx

// Task component - represents a single todo item
Task = React.createClass({
  propTypes: {
    // This component gets the task to display through a React prop.
    // We can use propTypes to indicate it is required
    task: React.PropTypes.object.isRequired
  },
  render() {
    return (
      <li>{this.props.task.text}</li>
    );
  }
});

+4
source share
1 answer

Wow, forgot to add "x" to the end of the file name. It should be "simple-todos-react.jsx". It would help if the error message was more understandable.

+6
source

Source: https://habr.com/ru/post/1611500/


All Articles