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}
      />
    
  )
}
5
  • 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. Commented Apr 8, 2022 at 7: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. Commented Apr 8, 2022 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? Commented Apr 9, 2022 at 8: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. Commented Apr 9, 2022 at 14:56
  • 1
    Nice. Please share a code snippet of your answer as it could help someone else in the future Commented Apr 9, 2022 at 15:20

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.