How to detect a click outside of a React Component (16.8+)

Поделиться
HTML-код
  • Опубликовано: 5 янв 2025

Комментарии •

  • @tylereikenberg9651
    @tylereikenberg9651 4 года назад

    This tutorial is perfect, I've been looking for something like this forever. Thank you so much!

  • @raulbarriga7416
    @raulbarriga7416 4 года назад

    Instead of setVisible on the if statement of the custom hook, would it be possible to add styling on the ref inside that if statement? I tried your implementation without setVisible & just to set some styles, but I'm getting an error 'TypeError: Cannot set property 'backgroundColor' of undefined' after I click on the ref div & then click outside it.

  • @NdifrekeEkim
    @NdifrekeEkim 4 года назад

    What happens if the element in document disables bubbling. Document will not receive the click event

  • @raba650
    @raba650 4 года назад

    This works but for some reason the button is requiring me to click twice to activate the drop down. The first click just selects the button. The 2nd click activates the drop down. Any suggestions anyone?

  • @cogwheelLearning
    @cogwheelLearning 4 года назад

    Hey, cool video! What program do you use for video editing and desktop recording?

  • @denmigod4625
    @denmigod4625 2 года назад

    thanks for the tutorial!

  • @Nanospeedz
    @Nanospeedz 4 года назад

    this is bad because the button is outside the div so if you try to toggle on the div through the button, the ref will reverse the boolean since the button is not the `current`

  • @pablod.1634
    @pablod.1634 3 года назад

    You saved my life!

  • @yanlukovsky9452
    @yanlukovsky9452 4 года назад +1

    Thanks, dude! it works)

  • @akashkadia8662
    @akashkadia8662 4 года назад

    Thank you so much, it can be very helpful

  • @veronicaperez308
    @veronicaperez308 4 года назад

    Thank you!

  • @joaodantas6225
    @joaodantas6225 3 года назад

    great tutorial, thanks :)

  • @bigenough2122
    @bigenough2122 4 года назад

    Thank you