'How to display UPDATE results immediatly
So here below i'm calling a query to update the slack_id. This is in the backend Index.js file. The /update is being called In the CRUD.js frontend in the next code segment.
app.put("/update", (req, res) => {
const id = req.body.id;
const slack_id = req.body.slack_id;
db.query( "UPDATE developers SET slack_id = ? WHERE id = ?",[slack_id, id],
(err, result) => {
if (err) {
console.log(err);
} else {
res.send(result);
}
}
);
});
The /update is called here. After the Axios.put I'm trying to put in a statement that can display the results immediatly without the need to refresh my page. I cant figure out how though. The setdeveloperList contains the values name, slack_id, selected, absent
I'm updating the slack_id here.
const updateDeveloper = (id) => {
Axios.put(`${url}/update`, { slack_id: newSlackID, id: id }).then(() => {
setdeveloperList(
developerList.filter((val) => {
return val.id !== id;
})
)
});
};
Solution 1:[1]
So I found out myself.
const updateDeveloper = (id) => {
Axios.put(`${url}/update`, { slack_id: newSlackID, id: id }).then(
(response) => {
setdeveloperList(
developerList.map((val) => {
return val.id === id
? {
id: val.id,
slack_id: newSlackID,
name: val.name,
selected: val.selected,
absent: val.absent
}
: val;
})
);
}
);
};
^^ This works
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Wake |
