Topic: how to Update data table after handeldelete methode .
sabri bargougui asked 4 years ago
state = { users: [], tableRows: [], }
async componentDidMount() {
await axios.get('http://localhost:3000/admin/users', {
headers: {
'x-access-token': localStorage.getItem("token")
}
}
)
.then(response => response.data)
.then(data => {
this.setState({ users: data })
})
.then(() => {
this.setState({ tableRows: this.getusers() })
});
}
getusers = () => {
let users = this.state.users.map((user) => {
return (
{
id: user._id,
name: user.name,
cin: user.cin,
delete: <MDBIcon
icon='trash'
className='red-text'
size='1x'
style={{ cursor: 'pointer' }}
onClick={() => this.handeldelete(user._id)}
/>,
add: <Analys />
}
)
});
return users;
}
handeldelete = async userId => {
await axios.delete("http://localhost:3000/admin/users/" + userId, {
headers: {
'x-access-token': localStorage.getItem("token")
}
})
this.getusers();
};
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Status
Open
Specification of the issue
- User: Free
- Premium support: No
- Technology: MDB React
- MDB Version: 5.0.1
- Device: pc
- Browser: chrome
- OS: windows 10
- Provided sample code: No
- Provided link: No
Tags
Related topics
Piotr Glejzer staff commented 4 years ago
do you have some errors in console about this problem?