Hi Guys ,
This blog is about the error " JSX expressions must have one parent element.
Let's look at the erroneous code .
You can see there are two elements <h1> and <input> .
The error is because react does not allow multiple component as a parent component . To fix this issue we can put the two elements under single parent component , like a <div> .
Let's fix the code .
The error is gone . Hope this helps , Thanks !
Checkout this error in youtube .
Let me know if you still face error in the comments below .
This blog is about the error " JSX expressions must have one parent element.
Let's look at the erroneous code .
import React from 'react';
export default ({ name }) => <h1>Hello {name}!</h1>
<input type="text" placeholder="enter asset"/>;
You can see there are two elements <h1> and <input> .
The error is because react does not allow multiple component as a parent component . To fix this issue we can put the two elements under single parent component , like a <div> .
Let's fix the code .
import React from 'react';
export default ({ name }) => <div><h1>Hello {name}!</h1>
<input type="text" placeholder="enter asset"/> </div>;
The error is gone . Hope this helps , Thanks !
Checkout this error in youtube .
Let me know if you still face error in the comments below .