O
O
oskar barin2019-08-29 10:57:36
React
oskar barin, 2019-08-29 10:57:36

How to change state in React?

There is such a state , it contains a multidimensional object

state = {
      data: {
        name: {value: name},
        mail: {value: email},
        text: 
          {value: { 
            title: subtitle,
            subtitle: subtitle,
            }
          },
      }
    }

How to write setState to change data.text.value.title?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2019-08-29
@madrogalo

this.setState(state => {
  const newState = { ...state }
  newState.data.text.value.title = 'new title'
  return newState
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question