class Game extends Component
{
constructor()
{
super()
this.state = {
speed: 0
}
//firebaseInit()
}
render()
{
return
(
The error - "Expected an assignment or function call and instead saw an expression no-unused-expressions" comes when we use curly braces i.e {} to return an object literal expression. In such case we can fix it with 2 options
Example :
const items = ["Test1", "Test2", "Test3", "Test4"];
console.log(articles.map(item => { `this is ${item}` })); // wrong
console.log(items.map(item => (`this is ${item}`))); // Option1
console.log(items.map(item => { return `this is ${item}` })); // Option2
In my case, I got the error on the setState line:
increment(){
this.setState(state => {
count: state.count + 1
});
}
I changed it to this, now it works
increment(){
this.setState(state => {
const count = state.count + 1
return {
count
};
});
}