https://youtu.be/NeTdlU0ZAzk
In React, wenn man vom HTML Code aus eine javascript
Function aufruft, bei welcher eine state-variable verwendet werden soll
Fehlermeldung:
Uncaught TypeError:
Cannot read properties of (reading 'state')
|
Falsch
onClickEdit(event) {
window.location.href = "/edit/" + this.state.idarticle;
}
|
Richtig
//*arrow()-function to get id
onClickEdit =
(event) => {
//alert('you clicked me');
//event.preventDefault(); //stops a href=url
window.location.href = "/edit/" + this.state.idarticle;
//later:browserHistory.push('/');
}
|
Aufruf aus dem Render() Block
<div style={{ float: 'right' }}>
<button type="button"
className="btn btn-primary" onClick={this.onClickEdit }>Edit</button>
</div>
|