Hi, am working on this for a while and can’t find a logical solution formyself. I am having a function that is called via onClick. It would interact with an API to delete an entry. When deleted, I want to re-render the list which includes the clicked element. The API works, I see it in my database. But I can’t get it to re-render, like…
- Item 1 → Remove
- Item 2 → Remove
I click on Remove in line with Item 2 it should re-render and show - Item 1 → Remove
The code below shows what I already have. I have removed some HTML because it is less relevant.
If anybody could tell me what I need to do I’d be really grateful.
function Grade() {
const [requests, setRequests] = useState([]);
const isMounted = useRef(true)
const [isSending, setIsSending] = useState(false)
function Postrating(skill_id, inviter, invitee, rating) {
var skillJSONObject = JSON.stringify({
"function": "xyx",
"post_user_id": invitee,
"get_user_id": inviter,
"skill_id": skill_id,
"skill_rating": rating
});
fetch("myURL", {
method: 'POST',
body: skillJSONObject,
})
.then(response => response.json())
.catch(error => {
console.error('Error:', error);
});
return () => setIsSending(!isSending);
}
useEffect(() => {
return () => {
isMounted.current = false
}
}, [])
useEffect(() => {
fetch('https://api.website.com, {
method: 'POST',
body: JSON.stringify({
"user_id": 1,
"mode": 1
}),
})
.then(response => response.json())
.then((data) => setRequests(data["response"]["data"]))
.catch(error => {
console.error('Error:', error);
});
}, []);
return <div className="pt-5">
<td class="px-6 py-4 text-center">
<button type="button" onClick={e=>Postrating(item.skill_id, item.user_id_inviter, item.user_id_invitee, 0)} className="text-blue-800 hover:underline">Skip</button>
}
export default Grade;