score:0

the function passed to this.props.companies.map isn’t an arrow function, so it creates a new this. change it to an arrow function to preserve the this from outside of it.

this.props.companies.map( ( item, i ) => { ... } )

you’ve also named the argument to onclick item, but it’s actually the click event. you want the item already defined by the map function. name the argument to onclick something else, or nothing, to avoid overwriting the item variable you actually want.

onclick={ () => { ... } }

score:2

make sure the function given to map is bound as well, or an arrow function:

{this.props.companies.map((item, i) => {
  return (
    <div>
      <div
        key={i}
        onclick={() => {
          this.setstate({ currentcompany: item });
        }}
      >
        {i}: {item.name}
      </div>

      <button>delete company</button>
    </div>
  );
})}

Related Query

More Query from same tag