Vitory Vit Votry
Vitory Vit Votry

Reputation: 1

error: line 8 parsing error unexpected token

unexpected token

I don't know where the error. I just followed the book.

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


class App extends Component 
{
return(
    <div>
        <HelloWorld />
        <HelloWorld />
        <HelloWorld />
    </div>
);
};

I want to know why this could be an error.

Upvotes: 0

Views: 332

Answers (1)

sebastienbarbier
sebastienbarbier

Reputation: 6832

Using React.Component, you need to define a render method to return your DOM. You can find more details on React.Component documentation.

class Welcome extends React.Component {
  render() {
    return <h1>Hello, {this.props.name}</h1>;
  }
}

You might have confused some examples with the new shiny syntax, react hooks, which now use a function object instead of a class object :

Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class.

import React, { useState } from 'react';

function Example() {
  // Declare a new state variable, which we'll call "count"
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}

Upvotes: 2

Related Questions