1

I created a function component and return JSX in react 18, but I was getting a strange warning; that "Unreachable code"

const Header = () => {
  return 
    <div className="header">
        <div className="container">
            <h1>hello</h1>
        </div>
    </div>;
  
    
};

export default Header;

I was thinking it happened because of the missing parenthesis "()" but when I added it

const Header = () => {
  return (
       <div className="header">
        <div className="container">
            <h1>hello world!</h1>
        </div>
    </div>;
  ) 
    
};

export default Header;

And the error I got was

Parsing error: Unexpected token, expected "," (8:10) ')' expected. Declaration or statement expected.

1 Answer 1

1

That was because I added an unexpected ";" after my JSX When I removed it, It worked

const Header = () => {
  return 
    <div className="header">
        <div className="container">
            <h1>hello</h1>
        </div>
    </div> 
  
    
};

export default Header;

or

const Header = () => {
  return (
       <div className="header">
        <div className="container">
            <h1>hello world!</h1>
        </div>
    </div>
  ) 
    
};

export default Header;

I only removed the ";" semicolon after the JSX in the return statement

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

1 Comment

Is it solves your problem?

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.