jsx – expected assignment or function call: no-unused-expressions ReactJS
jsx – expected assignment or function call: no-unused-expressions ReactJS
This happens because you put bracket of return
on the next line. That might be a common mistake if you write js without semicolons and use a style where you put opened braces on the next line.
Interpreter thinks that you return undefined and doesnt check your next line. Thats the return
operator thing.
Put your opened bracket on the same line with the return
.
In my case I had curly braces where it should have been parentheses.
const Button = () => {
<button>Hello world</button>
}
Where it should have been:
const Button = () => (
<button>Hello world</button>
)
The reason for this, as explained in the MDN Docs is that an arrow function wrapped by ()
will return the value it wraps, so if I wanted to use curly braces I had to add the return
keyword, like so:
const Button = () => {
return <button>Hello world</button>
}
jsx – expected assignment or function call: no-unused-expressions ReactJS
For me the error occured when using map. And I didnt use the return Statement inside the map.
{cart.map((cart_products,index) => {
<span>{cart_products.id}</span>;
})};
Above code produced error.
{cart.map((cart_products,index) => {
return (<span>{cart_products.id}</span>);
})};
Simply adding return solved it.