---
title: "Discussion on \"How to close the dropdown when clicked outside its division in React.\" | Hashnode"
description: "Discussion on \"How to close the dropdown when clicked outside its division in React.\". During my internship. One day I was working on building some dropdown filters for our company's product. Initially, I thought yeah it's not too big a deal. I can simply store one state and render the list on setting the state as true. So initial phas..."
url: "https://hashnode.com/posts/how-to-close-the-dropdown-when-clicked-outside-its-division-in-react/60117f452426ce41970734a1"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to close the dropdown when clicked outside its division in React.](https://shivamsharma.hashnode.dev/how-to-close-the-dropdown-when-clicked-outside-its-division-in-react?utm_source=hashnode&utm_medium=feed)

During my internship. One day I was working on building some dropdown filters for our company's product. Initially, I thought yeah it's not too big a deal. I can simply store one state and render the list on setting the state as true. So initial phas...

Jan 27, 2021 · 4 min read · shivamsharma.hashnode.dev  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#reactjs](https://hashnode.com/tag/reactjs)

## Written by

[Shivam Sharma](https://hashnode.com/@shvmsrma)

@shvmsrma · Hisar,Haryana,India

  
[View profile](https://hashnode.com/@shvmsrma)

Software Developer

I am Software Developer at ZettaBytes, Bangalore. I mainly work with Javascript.Have some understanding of React.

## Responses 1

Markdown supported · ⌘↵ to post

[Bhargav Ponnapalli](https://hashnode.com/@codewithbhargav)

[Jan 27, 2021](https://hashnode.com/posts/how-to-close-the-dropdown-when-clicked-outside-its-division-in-react/60117f452426ce41970734a1/comment/60118228c497f64171a4dc1f)

Good one [Shivam Sharma](https://hashnode.com/@shvmsrma).

I wrote a hook called to do this as well. Clicking outside is a very common feature for dropdowns, modals etc. So I made this hook.

[react-hooks.org/docs/use-outside-click-ref](https://react-hooks.org/docs/use-outside-click-ref/) Check it out if you get a chance!

Cheers!

[Shivam Sharma](https://hashnode.com/@shvmsrma)

[Jan 27, 2021](https://hashnode.com/posts/how-to-close-the-dropdown-when-clicked-outside-its-division-in-react/60117f452426ce41970734a1/comment/60118228c497f64171a4dc1f#reply-601188889cf50569ae1bda82)

Wow! that was pretty simple, surely gonna use it. Thanks:)

[Rutik Wankhade](https://hashnode.com/@rutikwankhade)

[Jan 28, 2021](https://hashnode.com/posts/how-to-close-the-dropdown-when-clicked-outside-its-division-in-react/60117f452426ce41970734a1/comment/60118228c497f64171a4dc1f#reply-601252a08b620b1d6bdf8420)

This is great. I needed this for modals. 🙌 Thanks [Bhargav Ponnapalli](https://hashnode.com/@imbhargav5)

[Bhargav Ponnapalli](https://hashnode.com/@codewithbhargav)

[Jan 28, 2021](https://hashnode.com/posts/how-to-close-the-dropdown-when-clicked-outside-its-division-in-react/60117f452426ce41970734a1/comment/60118228c497f64171a4dc1f#reply-6012536fe8f6da1d3fdfffe5)

Check out react-hooks.org. There should be quite a few hooks that you can use. Of course you can install all or one by one, they are ESM compatible so you won't have more hooks than you need in the final bundle. [Rutik Wankhade](https://hashnode.com/@rutikwankhade)
