So in react I made a button to delete some data so I need to get teh car by id and remove it by using react js axios so the response I got is an empty array so can some one help me please.
Here is the code :
in service data file :
get(id) {
return http.get(`/get/${id}`);
}
delete(id) {
return http.delete(`/delete/${id}`);
}
Component.jsx
this.state = {
idCars: null,
carName: "",
carModel: "",
cars: [],
submitted: false
};
}
getCar(idCars) {
DataService.get(idCars)
.then(response => {
this.setState({
cars: response.data
});
console.log(response.data);
})
.catch(e => {
console.log(e);
});
}
componentDidMount() {
this.getCar(this.props.match.params.idCars);
this.retrieveCars()
}
deleteC() {
DataService.delete(this.state.cars.idCars)
.then(response => {
this.props.history.push('/Classement');
this.refreshList()
})
.catch(e => {
console.log(e);
});
}
render() {
const { cars } = this.state;
return (
<div ><tbody>
{
cars.map(data => (
<tr >
<th scope="row">{data.idCars}</th>
<td>{data.carName}</td>
<td>{data.carModel}</td>
<td>
<button className="btn btn-danger" onClick={this.deleteC}>
Remove
</button>
</td>
</tr>
))
}
And doesn't remove nothing, how can I fix this guys