2

I am getting a parsing error when running my React app Failed to compile ./src/App.js Line 7: Parsing error: Unexpected token, expected "{"

I have checked my code for any unexpected token and did not see any.

    import React from 'react';
    import logo from './logo.svg';
    import './App.css';
    import './game.html';
    import Grid from './board.js';
    class App extends from React.Component {
        render(){
            return(
                     <div className="game-board">
                        <Grid/>
                     </div>
                  );
        }
    }
    export default App;


    import React from 'react';
    import Square from './square.js';
    class Grid extends React.Component{
        renderSquare(i)
        {
            return <Square value={i}/>
        }
        render(){
            <div className="gamerow">
                {this.renderSquare(1)}
                {this.renderSquare(2)}
                {this.renderSquare(3)}
            </div>
            <div className="gamerow">
                {this.renderSquare(4)}
                {this.renderSquare(5)}
                {this.renderSquare(6)}
            </div>
            <div className="gamerow">
                {this.renderSquare(7)}
                {this.renderSquare(8)}
                {this.renderSquare(9)}
            </div>
            }
    }
   export default Grid;


   import React from 'react';
  //import Grid  from './board.js
   class Square extends React.Component{
        render(){
            return(
                      <button className= "square">{this.props.value} 
                      </button>
                  );
        }
   }

export default Square; I am expecting the program to render a 3 by 3 grid on the UI.

2 Answers 2

3

There is no such keyword from when extending a class:

//                 v remove from
class App extends from React.Component` { ... }

Moreover, in Grid component, you need a return statement from render function, you can only render a single ReactElement, in this example I used <React.Fragment/> to group all <div/> elements.

class Grid extends React.Component {
  renderSquare(i) {
    return <Square value={i} />;
  }
  render() {
    return (
//    v <React.Fragment>
      <>
        <div className="gamerow">
          {this.renderSquare(1)}
          {this.renderSquare(2)}
          {this.renderSquare(3)}
        </div>
        <div className="gamerow">
          {this.renderSquare(4)}
          {this.renderSquare(5)}
          {this.renderSquare(6)}
        </div>
        <div className="gamerow">
          {this.renderSquare(7)}
          {this.renderSquare(8)}
          {this.renderSquare(9)}
        </div>
      </>
    )
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yea ty its the prettier :-(
1

Problem in below line.

class App extends from React.Component {

It should be look like below

class App extends React.Component {

Also you have to return the render method of Grid component.

Hope this will help you!

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.