Created
September 23, 2021 11:03
-
-
Save techomoro/352ad700473bf8464524f7faf5cf517a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from "react"; | |
import onClickOutside from "react-onclickoutside"; | |
import DropdownList from "./DropDownList"; | |
function DropdownLink(props) { | |
const [showDropdown, setShowDropdown] = useState(false); | |
DropdownLink.handleClickOutside = () => { | |
setShowDropdown(false); | |
}; | |
return ( | |
<div> | |
<div | |
class="nav-item nav-link profile-link" | |
onClick={() => setShowDropdown(!showDropdown)} | |
> | |
John | |
</div> | |
{showDropdown ? <DropdownList /> : null} | |
</div> | |
); | |
} | |
const clickOutsideConfig = { | |
handleClickOutside: () => DropdownLink.handleClickOutside, | |
}; | |
export default onClickOutside(DropdownLink, clickOutsideConfig); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment