How to use the react-use.useClickAway function in react-use

To help you get started, we’ve selected a few react-use examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github laravelcm / website / resources / assets / ts / components / AccountDropdown.tsx View on Github external
export default () => {
  const [isOpen, setIsOpen] = useState(false);
  const { auth: { user } } = usePage();
  const ref = useRef(null);
  const closeDropdown = () => {
    setIsOpen(false);
  };

  useClickAway(ref, closeDropdown);
  const {
    picture,
    email,
    full_name,
    is_admin,
    // username,
  }: User = user;

  return (
    <div>
      <button> setIsOpen(!isOpen)}
        className="block h-10 w-10 rounded-full border-2 border-gray-200 overflow-hidden relative z-10"
      &gt;
        </button></div>
github 0xTracker / 0x-tracker-client / src / features / header / components / header-search.js View on Github external
const HeaderSearch = ({ onBlur, onSearch }) =&gt; {
  const wrapperRef = useRef();

  useClickAway(wrapperRef, onBlur);
  useEscapeKey(onBlur);

  return (
    <div>
      
        {({ currentValue, handleChange, handleSubmit }) =&gt; (
          &lt;&gt;
            
              </div>
github codesandbox / codesandbox-client / packages / app / src / app / pages / Sandbox / Editor / Workspace / Project / SandboxConfig / TemplateConfig.tsx View on Github external
currentSandbox: { customTemplate, template },
      },
    },
  } = useOvermind();
  const picker = useRef(null);
  const [showPicker, setShowPicker] = useState(false);
  const [selectedColor, setSelectedColor] = useState(
    () =&gt; customTemplate.color || templates.default(template).color()
  );

  const colors = Object.keys(templates)
    .filter(x =&gt; x !== 'default')
    .map(t =&gt; templates[t])
    .map(a =&gt; ({ color: a.color(), title: a.niceName }));

  useClickAway(picker, () =&gt; {
    setShowPicker(false);

    editTemplate({
      ...customTemplate,
      color: selectedColor,
    });
  });

  return (
    
      
        This is a template, you can find more info about templates{' '}
        
          here
        
        .
github laravelcm / website / resources / assets / ts / includes / Header.tsx View on Github external
export default () =&gt; {
  const [isOpen, setIsOpen] = useState(false);
  const [show, setShow] = useState(false);
  const [loader, setLoader] = useState(false);
  const [query, setQuery] = useState('');
  const [results, setResults] = useState([]);
  const { auth } = usePage();
  const input = useRef(null);
  const ref = useRef(null);
  const closeDropdown = () =&gt; {
    setShow(false);
  };
  useClickAway(ref, closeDropdown);

  const onKeyDown = (e: KeyboardEvent) =&gt; {
    if (e.code === "Backslash") {
      e.preventDefault();
      if (input.current) {
        const element = input.current;
        element.focus();
      }
    }
  };

  function handleChange(e: React.ChangeEvent) {
    const { value } = e.target;
    setQuery(e.target.value);

    if (value &amp;&amp; value.length &gt; 3) {