2

I don't know why i am getting this error can someone please help i have checked the syntax and cant find anything wrong. It's probably something stupid but i just can't find what it is.

import React, { Component } from 'react';
//import Node from './Node/Node';
import { render } from 'react-dom'

import './Pathfinder.css';

export default class Pathfinder extends Component {
   constructor(props){
    super(props);
    this.state = {
        grid: [], 
};
}
}

render(); {

    return (
        <div>
            {this.startGrid()}
        </div>
    );

}```

0

2 Answers 2

4

I think that you copy-n-paste the code, but you messed up with the curly braces.

import React, { Component } from 'react';
//import Node from './Node/Node';
import { render } from 'react-dom'

import './Pathfinder.css';

export default class Pathfinder extends Component {
   constructor(props){
       super(props);
       this.state = {
           grid: [], 
       };
   }
   } <-- should be removed

   render() { <-- remove the ; sign
       return (
           <div>
             {this.startGrid()}
           </div>
       );
    }
} <-- close your component with curly braces

Tip for every code: Use the correct indentation. Tip for some codes: Use a linter with prettier.

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

Comments

3

Issue is semicolon after the render keyword.

And render method is outside the class component due to wrongly placed brackets

render(); {}

Change it to

render() {}

Code should look like :

    import React, { Component } from 'react';
    //import Node from './Node/Node';
    import { render } from 'react-dom'
    
    import './Pathfinder.css';
    
    export default class Pathfinder extends Component {
       constructor(props){
        super(props);
        this.state = {
            grid: [], 
    };
    }
  
    
    render() {
    
        return (
            <div>
                {this.startGrid()}
            </div>
        );
    
    }
 }

3 Comments

when i take the semicolon away the compiler starts giving me errors so i kept it in there but its stupid. it comes up as a syntax error
yeh that works fine thanks and sorry i accidentally deleted your comment earlier
Awesome. Glad it helped you . I hope you wont mind accepting the answer and upvoting it

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.