new there. I started learning React and I have a code problem - I can't figure it out. I tried to find the problem here:
https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Functions/Arrow_functions
I perform a bind - and send the function to another component.
{this.state.array.map((char, index) => <CharComponent style={mystyle} character={char} click={(index) => this.deleteHandler(index)} key={index}></CharComponent>)}
deleteHandler = (index) => {
let copyArray = [...this.state.array];
console.log('copyArray: ' + copyArray);
copyArray.splice(index, 1);
console.log('copyArray: ' + copyArray);
this.setState({ length: copyArray.length, string: copyArray.join(''), array: copyArray });
}
I can not get the index - it shows me that it is an object and not a number.
I did a bind - I sent the index as a parameter - and then called it in the function
Why should the brackets be empty? click={(index) => this.deleteHandler(index)