score:1

Accepted answer

you can reach that this way:

let navlist = this.state.navlist;
navlist.map(item => {
  if (item.name === 'nelayan') {
    item.child = // the data you want in array
  }
  return item;
});
this.setstate({ navlist })

first, make a copy.
then, you should go over each item in array and compare with the data you want to change, for example the item called 'nelayan', and then update the content and return it to the array. and last set the new state with the new array.

note: you need an unique identifier to do that and be sure you are updating just the item you wanna do it for.

class app extends component {
  constructor(props) {
    super(props);
    this.state = {
      personas: [
        { id: 1, nombre: "adolfo" },
        { id: 2, nombre: "juan" }
      ]
    }
  }

  componentdidmount() {
    console.log("componentdidmount")
    let personas = this.state.personas
    personas.foreach(item => {
      if (item.id === 2) item.nombre = "jose"
      return item
    })
    this.setstate({ personas })
  }


  render() {
    console.log(this.state.personas)
    return (
      <div classname="app">
        <header classname="app-header">
          <img src={logo} classname="app-logo" alt="logo" />
          <h1 classname="app-title">welcome to react</h1>
        </header>
        <div classname="app-intro">
          { 
            this.state.personas 
            ? this.state.personas.map((item, index) => {
              return <p key={index}>
                {this.state.personas[index].id} - {this.state.personas[index].nombre}
              </p>         
            })
            : ''
          }
        </div>
        {this.state.info ? this.state.info : 'no tengo info'}
      </div>
    );
  }
}

Related Query

More Query from same tag