Answer the question
In order to leave comments, you need to log in
How to fix the error Expected an assignment or function call and instead saw an expression?
I created a takeInfo function that, when clicking on a product, compares its price with the price from this.props.cats and returns the product that came up to me, so that I can then display it somewhere, but the error "Expected an assignment or function call and instead saw an expression" pops up ". Why? I don’t have to return anything, but simply write the object to the state in order to use it further
export class Cat extends React.Component {
state = {
catsImg: imgArr,
kittie: this.props.cats,
catInfo: [ ],
}
takeInfo = (catPrice) => {
this.setState(state => ({
catInfo: {...state.kittie.filter(cat=>{
catPrice === cat.total
})}
}))
}
<button onClick={() => {
this.takeInfo(cat.total)
}}>Buy</button>
Answer the question
In order to leave comments, you need to log in
Maybe this will help? (= your {...} and [...] are not the same)
catInfo: state.kittie.filter(cat => catPrice === cat.total)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question