D
D
drotsyk2021-01-26 13:51:27
React
drotsyk, 2021-01-26 13:51:27

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
      })}
    }))
  }

the button looks like this
<button onClick={() => {
     this.takeInfo(cat.total)
}}>Buy</button>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Pastukhov, 2021-01-26
@drotsyk

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 question

Ask a Question

731 491 924 answers to any question