This content originally appeared on CodeSource.io and was authored by Pandu Rijal Pasa
This article will help you to fix jsx expressions must have one parent element error on React.
The main reason this error happened is that you try to return a JSX expression with two (or more) elements as a root. It said, the component looks like this:
const MyComponent = () => {
return (
<div>Element 1</div>
<div>Element 1</div>
)};
This can be fixed by wrapping the component with one single tag, we can use <React.Fragment />
or simply use the short syntax <></>
. Here is the example:
const MyComponent = () => {
return (
<>
<div>Element 1</div>
<div>Element 1</div>
</>
)};
The post Fix – jsx expressions must have one parent element appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Pandu Rijal Pasa
Pandu Rijal Pasa | Sciencx (2021-02-20T11:06:22+00:00) Fix – jsx expressions must have one parent element. Retrieved from https://www.scien.cx/2021/02/20/fix-jsx-expressions-must-have-one-parent-element/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.