Thursday, August 15, 2019

Parsing error: Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...?

class App extends React.Component {
render() {
return (
<Header />
<Content/>
);
}
}

This code throw error as follow :

./src/App.js
  Line 9:  Parsing error: Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>?

   7 |     return (
   8 |     
> 9 | | ^ 10 | ); 11 | } 12 | }

to solve that error that you need to put your component tags into elclosing tags
like this
return (
    <div>
       <Comp1 />
       <Comp2 />
    </div>
)
or you can use the <React.Fragment>
return (
    <React.Fragment>
       <Comp1 />
       <Comp2 />
    </React.Fragment>
) 

https://reactjs.org/docs/fragments.html 






No comments:

Post a Comment

ASP.NET Core

 Certainly! Here are 10 advanced .NET Core interview questions covering various topics: 1. **ASP.NET Core Middleware Pipeline**: Explain the...