0

I am using slate.js and when I delete an image by pressing backspace the image is removed from state and no longer exists. However, with the image still being stored on the server. I would like to trigger an event to delete the image from the server.

I have my image element below where I have got the image id. I want an event to be triggered on delete so I can use that id to delete the image from the backend.

export const ImageElement = ({ attributes, element }) => {

  return (
      <img
id='imageid'
        className="rounded "
        alt="uploaded image"
        src={element.url}
      />
    
  )
}
  • You would need to send a request to your `delete` route in your backend that should use the id to search the database and remove the said image from the database. – Sebastian Gbudje Apr 08 '22 at 07:13
  • @SebastianGbudje Ive got a delete route set up but when you backspace an image in slate js it gets removed from the state. I dont know how to trigger a certain event for its deletion though. – coder5666666666 Apr 08 '22 at 18:21
  • So when you delete the image it doesn't leave the UI is what you are saying or it doesn't get removed from the DB? – Sebastian Gbudje Apr 09 '22 at 08:20
  • @SebastianGbudje Hi, the issue was that the image got removed from the ui. I saved the value in the db but the image was saved elsewhere in the db. I used react component unmount to solve the issue. – coder5666666666 Apr 09 '22 at 14:56
  • 1
    Nice. Please share a code snippet of your answer as it could help someone else in the future – Sebastian Gbudje Apr 09 '22 at 15:20

1 Answers1

0

In slate.js for any element that gets removed from the state. You can use component unmounts in react on the component and trigger any deletion events from there.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 09 '22 at 16:55