class Game extends Component
{
constructor()
{
super()
this.state = {
speed: 0
}
//firebaseInit()
}
render()
{
return
(
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 doesn't check your next line. That's 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>
}
For me the error occured when using map. And I didn't 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.
In my case I have got this error, because used a call inside of the condition without a semicolon:
private async _setActive(active: boolean) {
if (this.isActive === active) {
return;
}
this.isActive = active;
this.isActive ? this._start() : this._stop();
}
I changed it, and the error has gone:
private async _setActive(active: boolean) {
if (this.isActive === active) {
return;
}
this.isActive = active;
if (this.isActive) {
await this._start();
} else {
this._stop();
}
}
I encountered the same error, with the below code.
return this.state.employees.map((employee) => {
<option value={employee.id}>
{employee.name}
</option>
});
Above issue got resolved, when I changed curly braces to parenthesis, as indicated in the below modified code snippet.
return this.state.employees.map((employee) => (
<option value={employee.id}>
{employee.name}
</option>
));
If You're using JSX inside a function with curly braces you need to modify it to parenthesis.
Wrong Code
return this.props.todos.map((todo) => {
<h3> {todo.author} </h3>;
});
Correct Code
//Change Curly Brace To Paranthesis change {} to => ()
return this.props.todos.map((todo) => (
<h3> {todo.author} </h3>;
));