Giter Site home page Giter Site logo

Comments (2)

srmagura avatar srmagura commented on May 24, 2024 1

Hey @tonix-tuft, your analysis is correct. Is the hook's current implementation causing any issues?

We use useRef for the reason you said: If a new handler is defined on each render, we want to avoid adding and removing the event listener on each render.

Your implementation would work too. The caller would always need to remember to useCallback to prevent lots of unnecessary addEventListener / removeEventListener calls. The problem is most people (myself included) are not going to remember to useCallback every single time.

from use-event-listener.

tonix-tuft avatar tonix-tuft commented on May 24, 2024 1

No no, I was just curious and asked about the design decisions of this hook, no issues. Closing this.

Thank you for your reply!

from use-event-listener.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.