1

I was new in ReactJS and I want to learn the basics from Traversy Media's video tutorial and I apply the code exactly what he have to do. But I got stuck in this part because I got an error Failed to Compile like this: Failed to compile

This is the code I have written:

App.js

import React, { Component } from 'react';
import Todos from './components/Todos';
import './App.css';

class App extends Component {
  state = {
   todos: [
     {
       id: 1,
       title: 'Take out he trash',
       completed: false
     },
     {
       id: 2,
       title: 'Have a Dinner',
       completed: false
     },
     {
       id: 3,
       title: 'Meeting with Boss',
       completed: false
     },
   ]
  };

  render() {
    return (
      <div className="App">
        <Todos todos={this.state.todos} />
      </div>
    );
  }
}

export default App;

Todos.js

import React, {Component} from 'react';
import TodoItem           from './TodoItem';

class Todos extends Component {
  render() {
    return this.props.todos.map((todo) => (
      <TodoItem/>
    ));
  }
}

export default Todos;

TodoItem.js

import React, { Component } from 'react';

export class TodoItem extends Component{
  render(){
    return{
      <div>
        <p>Hello</p>
      </div>
    }
  }
}

export default TodoItem;

3 Answers 3

2

It should look like that -

import React, { Component } from 'react';

export class TodoItem extends Component{
  render(){
    return(
      <div>
        <p>Hello</p>
      </div>
    )
  }
}

export default TodoItem;

Sign up to request clarification or add additional context in comments.

Comments

2

It should be

return(
  <div>
    <p>Hello</p>
  </div>
)

Use braces for methods or variables

3 Comments

So it was my mistakes. Thanks for helping.
Okay please upvote this post to help others also... And so I can have some cool points
Or Check it as an answer
1

There is a syntax error in TodoItem.js return statement. Just replace this code

    import React, { Component } from 'react';

     export class TodoItem extends Component{
       render(){
         return(
           <div>
            <p>Hello</p>
           </div>
               )
             }
           }

      export default TodoItem;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.