Fix – jsx expressions must have one parent element

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…

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

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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Fix – jsx expressions must have one parent element." Pandu Rijal Pasa | Sciencx - Saturday February 20, 2021, https://www.scien.cx/2021/02/20/fix-jsx-expressions-must-have-one-parent-element/
HARVARD
Pandu Rijal Pasa | Sciencx Saturday February 20, 2021 » Fix – jsx expressions must have one parent element., viewed ,<https://www.scien.cx/2021/02/20/fix-jsx-expressions-must-have-one-parent-element/>
VANCOUVER
Pandu Rijal Pasa | Sciencx - » Fix – jsx expressions must have one parent element. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/20/fix-jsx-expressions-must-have-one-parent-element/
CHICAGO
" » Fix – jsx expressions must have one parent element." Pandu Rijal Pasa | Sciencx - Accessed . https://www.scien.cx/2021/02/20/fix-jsx-expressions-must-have-one-parent-element/
IEEE
" » Fix – jsx expressions must have one parent element." Pandu Rijal Pasa | Sciencx [Online]. Available: https://www.scien.cx/2021/02/20/fix-jsx-expressions-must-have-one-parent-element/. [Accessed: ]
rf:citation
» Fix – jsx expressions must have one parent element | Pandu Rijal Pasa | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.