Encountering a parsing issue within my React program

I keep encountering a parsing error while trying to run my React application The compilation fails with the following error message: ./src/App.js Line 7: Parsing error: Unexpected token, expected "{"

After reviewing my code, I couldn't find any unexpected tokens.


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>
        );
    }
}

I have added 'export default Square;' line in anticipation of displaying a 3 by 3 grid on the UI.

Answer №1

When extending a class, it's important to note that the keyword from is not valid:

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

Additionally, in the Grid component, remember to include a return statement within the render function. You can only render a single ReactElement. In this example, I used <React.Fragment/> to group all the <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>
      </>
    )
  }
}

Answer №2

There seems to be an issue with the following line.

class App extends from React.Component {

The correct syntax should be as follows:

class App extends React.Component {

In addition, make sure you return the render method of the Grid component.

I hope this information helps resolve your problem!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using JavaScript to connect SQL query results to a specific function

Hello everyone, I find myself in a bit of a pickle while working with WebOS enyo. Although the fact that I am using enyo is irrelevant to my question... Here is a method I have: clickPopulate: function(){ // Do some SQL }; I am utilizing a data ...

What could be causing the onclick function in the button tag to malfunction?

I have implemented a feature where clicking on a "Delete Photo" button would trigger the appearance of another delete button in the code. The code for this functionality is as follows: <button type="button" class="btn btn-danger" onc ...

The function ng-click does not successfully uncheck ion-radio

In the process of developing my application using the ionic framework, I encountered a challenge where I needed to deselect an ion-radio button when clicking on an input tag. Despite attempting to achieve this functionality through this ionic play link, I ...

Arranging expandable divs horizontally

Looking for a way to align these blocks so they can expand while remaining in line, I'm struggling with maintaining their individual spaces. The layout I have in mind is as follows: In this setup, box 2 and 3 should automatically adjust to fill the a ...

The entered value in the <input> field is not valid

I am encountering an issue where the input value is auto-filled, but when I click the submit button, the input field value is not recognized unless I modify something in it, such as deleting and adding the last word to the first name. Is there a way to m ...

Displaying MySQL results in a vertical sequence

I've stored the data in my database as follows: Football ART-NR-1337 Price: 5$ Basketball ART-NR-1333 Price: 10$ Now, I am working on a .php file that displays the articles like this: Football Basketball ART-NR-1337 ART-NR-1333 Price: 5$ ...

The mp4 video on the website will only load if the Chrome developer tools are activated

Whenever I try to play the video set as the background of the div, it only starts playing if I refresh the page with Chrome dev tools open. HTML: <div id="videoDiv"> <div id="videoBlock"> <img src="" id="vidSub"> <video preload="prel ...

The onclick functionality is not functioning properly within email communications

My JavaScript code contains an AJAX call within Datatables, and this snippet of code is causing an issue: { "data": null, "width": "10%", "render": function(data){ icon2 = '<center><button type="button" class="btn btn-info ...

Tips on managing JavaScript pop-up windows with Selenium and Java

There have been numerous solutions provided on Stack Overflow for handling JavaScript windows, but my situation is quite unique. I am currently working on automating a process for our web-based application. The development team recently implemented a MODA ...

Optimal method for utilizing state information post-update

After updating my application to utilize the useReducer hook, I encountered an issue with running code following state updates. The problem is discussed in detail here. The suggested solution involves extracting the 'nextState' by manually invok ...

What is the best way to create a mobile menu transition that moves in a "reverse" direction?

I have been working on animating a mobile menu where the three stripes transform into an 'X' when clicked and revert back to three stripes when closed. The transition to an 'X' is working perfectly, but when closing the menu, it jumps b ...

Using 2 distinct versions of a single node dependency in package.json - a comprehensive guide

Currently, I am developing a react js application in which I have implemented Material-UI v5.0.0 for all my UI components. This new version has introduced changes in the package names, replacing @material-ui/* with @mui/*: @material-ui/system -> @mui/sy ...

Incorporating debounce functionality in React text input using lodash throttle and Typescript

I've been having trouble getting this text input throttle to function properly in my React project, despite spending a considerable amount of time reading documentation. import { throttle } from 'lodash'; ... <input type="t ...

Transmitting an array within the POST request payload

My goal is to send an array to my Node/MongoDB server using an AJAX POST request, along with other variables in the body. Check out the client side JS code below: function setupForm(){ $("#add").submit(function(event) { event.preventDefault() ...

Ways to layer two divs on each other and ensure button functionality is maintained

In the process of developing a ReactJS project, I encountered the challenge of overlapping my search bar autocomplete data with the result div located directly below it. For a more detailed understanding, please take a look at the provided image. Here&apo ...

Remove the initial DIV element from the HTML code

I have created a unique chat interface by combining JScript, php, and jquery. The chat messages are saved in an HTML document that gets displayed in the text area. Each user input message is contained within its individual div tag: <div>Message</ ...

The requested property map cannot be found within the Array

I am working on a project using redux with react typescript. I have an external JSON file that contains employee data categorized by department id. To properly map the data with types in my application, I have created specific types. Check out this demo o ...

Adjusting the spacing around the title of a post when the text wraps

This website has some great resources, check it out! In the right sidebar, there seems to be an issue with the CSS when the h4 heading wraps onto two lines. The margin and padding at the bottom of the heading are not spacing properly. I've tried adju ...

"Exploring the Visual World: Utilizing Images in React

Recently, I developed a react native component and packaged it for npm following this guide: https://www.freecodecamp.org/news/how-to-publish-a-react-native-component-to-npm-its-easier-than-you-think-51f6ae1ef850/ Subsequently, I created a new react nati ...

RSS eluded HTML

My interpretation of RSS's "escaped HTML" is when code like this appears: HTML: 1 &lt; 3 Is transformed in RSS to: 1 &amp;lt; 3 So, the question arises, should this: <img src="http://somehost/someimage?a=foo&amp;b=bar" /> Be c ...