Skip to content

Instantly share code, notes, and snippets.

View anpct's full-sized avatar
🎯
Focusing

Anoop Christopher Thiparala anpct

🎯
Focusing
View GitHub Profile
@anpct
anpct / Dropdown.js
Created November 3, 2021 19:10
Reusable Dropdown
import React, { useState } from "react";
import useListener from "../../hooks/useListener";
import styled from "styled-components";
const DropdownContainer = styled.div`
width: 100px;
height: 100%;
position: relative;
display: flex;
align-items: center;
@anpct
anpct / useListener.js
Last active November 3, 2021 19:04
useListener
import { useEffect, useRef } from "react";
const useListener = (outsideFunction) => {
const ref = useRef();
useEffect(() => {
const handleClick = (event) => {
if (ref.current && ref.current.contains(event.target)) {
return;
}