So I can get the button through the event when it is clicked on. But when I do a filter, it does not remove the said button.
So I have my array in the constructor():
First of all, you need to bind this to the scope of your callback function. If you want to access the react object instance used to render the button from the synthetic event, you can do so using the private variable _targetInst.
class Buttons extends React.Component{
constructor(props) {
super(props);
this.delete_me = this.delete_me.bind(this);
this.state = {
buttons : [,]
};
}
delete_me(e){
const buttons = this.state.buttons.filter((button) => button != e._targetInst._currentElement);
this.setState({ buttons });
}
render() {
return {this.state.buttons};
}
};
ReactDOM.render(
,
document.getElementById('container')
);
However, as Chris mentioned, your approach is not very much in line with the React patterns, and you should avoid accessing private methods or properties (usually named with an underscore)