B
B
bmg012020-11-06 14:30:17
React
bmg01, 2020-11-06 14:30:17

I can not understand one topic on react What should I do?

const database = [
{
id: 1,
name: "TV",
price: 100000,
bought: false,
rating: 4,
},
{
id: 2,
name: "Car",
price: 315999,
bought: false,
rating: 4,
}


You need to create a function that takes one parameter, which is passed the `id` of the desired product.

The function must rewrite the state where the `bought` field in the object with the specified `id` is replaced with `true`.
I apologize in advance because I'm green in this business

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xenonhammer, 2020-11-06
@bmg01

const [database, setDatabase] = useState()

function qweqwe (id){
  setDatabase(database.map(e => {
      if(e.id === id) {
          e.bought = true
      }
      return e
  })
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question