Hello,
I need help in button delete
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import api from '../../services/api'
export default class Index extends Component {
constructor(props) {
super(props);
this.onDeleteId = this.onDeleteId.bind(this);
this.state = { motoristas: [] };
}
async componentDidMount() {
try {
const response = await api.get('/motoristas');
this.setState({ motoristas: response.data })
}
catch (error) {
console.log(error)
}
}
onDeleteId(e) {
this.setState({
ID_MOTORISTA: e.target.value
});
}
delete() {
try {
api.delete('/motoristas/' + this.props.id)
}
catch (error) {
console.log(error)
}
//this.props.history.push('/PesquisarMot');
}
render() {
return (
<div>
<h3 align="center">Motoristas</h3>
<table className="table table-striped" style={{ marginTop: 20 }}>
<thead>
<tr>
<th>ID</th>
<th>Motorista</th>
<th>Celular</th>
<th>CPF</th>
<th>RG</th>
<th>Categoria</th>
<th>Data</th>
<th colSpan="2">Ações</th>
</tr>
</thead>
<tbody>{
this.state.motoristas.map(motorista => (
<tr key={motorista.ID_MOTORISTA}>
<td>
{motorista.ID_MOTORISTA}
</td>
<td>
{motorista.NM_MOTORISTA}
</td>
<td>
{motorista.CEL_MOTORISTA}
</td>
<td>
{motorista.CPF_MOTORISTA}
</td>
<td>
{motorista.RG_MOTORISTA}
</td>
<td>
{motorista.CATEGORIACNH_MOTORISTA}
</td>
<td>
{motorista.DATA_NASC_MOTORISTA}
</td>
<td>
<Link to={`/atualizarMot/${motorista.ID_MOTORISTA}`}><button className="btn btn-primary">Editar</button></Link>
</td>
<td>
<button className="btn btn-danger" id={motorista.ID_MOTORISTA} onClick={this.delete}>Excluir</button>
</td>
</tr>))}
</tbody>
</table>
</div>
);
}
}import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import api from '../../services/api'
export default class Index extends Component {
constructor(props) {
super(props);
this.onDeleteId = this.onDeleteId.bind(this);
this.state = { motoristas: [] };
}
async componentDidMount() {
try {
const response = await api.get('/motoristas');
this.setState({ motoristas: response.data })
}
catch (error) {
console.log(error)
}
}
onDeleteId(e) {
this.setState({
ID_MOTORISTA: e.target.value
});
}
delete() {
try {
api.delete('/motoristas/' + this.props.id)
}
catch (error) {
console.log(error)
}
//this.props.history.push('/PesquisarMot');
}
render() {
return (
<div>
<h3 align="center">Motoristas</h3>
<table className="table table-striped" style={{ marginTop: 20 }}>
<thead>
<tr>
<th>ID</th>
<th>Motorista</th>
<th>Celular</th>
<th>CPF</th>
<th>RG</th>
<th>Categoria</th>
<th>Data</th>
<th colSpan="2">Ações</th>
</tr>
</thead>
<tbody>{
this.state.motoristas.map(motorista => (
<tr key={motorista.ID_MOTORISTA}>
<td>
{motorista.ID_MOTORISTA}
</td>
<td>
{motorista.NM_MOTORISTA}
</td>
<td>
{motorista.CEL_MOTORISTA}
</td>
<td>
{motorista.CPF_MOTORISTA}
</td>
<td>
{motorista.RG_MOTORISTA}
</td>
<td>
{motorista.CATEGORIACNH_MOTORISTA}
</td>
<td>
{motorista.DATA_NASC_MOTORISTA}
</td>
<td>
<Link to={`/atualizarMot/${motorista.ID_MOTORISTA}`}><button className="btn btn-primary">Editar</button></Link>
</td>
<td>
<button className="btn btn-danger" id={motorista.ID_MOTORISTA} onClick={this.delete}>Excluir</button>
</td>
</tr>))}
</tbody>
</table>
</div>
);
}
}