I want to try deleting the technologies data according to the index using the handleDeleteTechnology function but when I try to delete it and it works if I see the data in the data, but in the UI what is deleted is always the last index even though I want to delete the first index.
const handleDeleteTechnology = (index) => {
const updatedTechnologies = [...technologies];
updatedTechnologies.splice(index, 1);
setTechnologies(updatedTechnologies);
const updatedDetailTechData = [...detailTechData];
updatedDetailTechData.splice(index, 1);
setDetailTechData(updatedDetailTechData);
return setFilesTech(prevFilesTech => {
const updatedFilesTech = [...prevFilesTech];
updatedFilesTech.splice(index, 1);
return updatedFilesTech;
});
};
{technologies.map((tech, index) => (
<div className='flex' key={index} index={index}>
<div className='relative'>
<FaCircleMinus size={25} className='absolute -top-2 -left-2 text-red-600' onClick={() => handleDeleteTechnology(index)} />
</div>
<UploadTechnology
index={index}
technology={tech}
onImageChange={(index, imageUrl) => handleImageChange(index, imageUrl)}
/>
</div>
))}
I've tried searching on Google or chatgpt but still haven't found this problem