Skip navigation
Stop using document.removeEventListener() 😤
0:00 / 0:53

Stop using document.removeEventListener() 😤

Ben Holmes

@BHolmesDev39K followers

Visit on X
709 likesDownloadOriginal post

68,287 views

Stop using document.removeEventListener() 😤

11 Comments

Comments from the original post on X (Twitter)

  • Ben Holmes's profile picture

    @BHolmesDev

    Thanks for the tip @mattpocockuk

    86 likes

  • PDF GPT's profile picture

    @pdfgptsupport

    This is my favorite AI tool for reviewing reports. Just upload a report, ask for a summary, and get one in seconds. It's like ChatGPT, but built for documents. Try it for free.

    13,200 likes

  • Alex MacArthur's profile picture

    @amacarthur

    You can use the same signal to nuke multiple listeners at once too!

    43 likes

  • samuel 🦋's profile picture

    @mozzius

    holy shit thank you for this

    12 likes

  • José Breijo's profile picture

    @josebreijo

    With `removeEventListener`, your codebase has a predictable 1:1 explicit relationship. It is declarative, and that is what it was intended for. Instead, an abortable signal is an optional argument; you need to carry it around, too, and manually kill listeners (malloc PTSD). Fashionable or more terse approaches are cool, but they are not always justified, at least not for me, like lambdas vs. function declarations.

    8 likes

  • Mantas's profile picture

    @coolemur

    I don't know why, but this looks cleaner. Probably because event is removed in same way how it was added, not using some separate abortController object which is then passed as param to addEventListener...

    7 likes

  • JLarky's profile picture

    @JLarky

    The poor whiteboard got out of the frame :-(

    4 likes

  • Marius Vatasoiu's profile picture

    @MariusVatasoiu

    All good and then you find out you need to support Safari 14 💀

    3 likes

  • Iván Tajes Vidal's profile picture

    @tajespasarela

    Just stop using React!

    2 likes

  • Aaron's profile picture

    @Aaron9305631176

    I wouldn't say "Stop using", instead, "here's another way to achieve a slightly similar effect but not exactly the same that may or not may not suite your use case" although where's the twitter friendly way on how to communicate that :p

    2 likes

  • Moshe Schnitzler's profile picture

    @SchnitzlerMoshe

    Practically speaking, how can pass in a AbortListener to clean my dishes?

    1 like