<commit_before>import { useEffect } from 'react';
import { addEvent, removeEvent } from './listenerHelpers';

export function useOutsideClick(ref, callback) {
  useEffect(() => {
    const listener = event => {
      if (!ref.current || ref.current.contains(event.target)) {
        return;
      }
      callback();
    };
    addEvent(document, 'mouseup', listener);
    addEvent(document, 'touchend', listener);
    return () => {
      removeEvent(document, 'mouseup', listener);
      removeEvent(document, 'touchend', listener);
    };
  });
}<commit_msg>minor fix<commit_after>import { useEffect, useState } from 'react';
import { addEvent, removeEvent } from './listenerHelpers';

export function useOutsideClick(ref, callback) {
  const [insideClicked, setInsideClicked] = useState(false);
  useEffect(() => {
    function uPlistener(event) {
      if (insideClicked) return setInsideClicked(false);
      if (!ref.current || ref.current.contains(event.target)) {
        return;
      }
      callback();
    }
    function downListener(event) {
      if (ref.current?.contains(event.target)) {
        setInsideClicked(true);
      }
    }
    addEvent(document, 'mousedown', downListener);
    addEvent(document, 'mouseup', uPlistener);
    addEvent(document, 'touchend', uPlistener);
    return () => {
      removeEvent(document, 'mousedown', downListener);
      removeEvent(document, 'mouseup', uPlistener);
      removeEvent(document, 'touchend', uPlistener);
    };
  });
}
{'fraction_non_alphanumeric': 0.14621059691482227, 'fraction_numerical': 0.0, 'mean_word_length': 3.562691131498471, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4085426', 'n_tokens_mistral': 451, 'n_tokens_neox': 448, 'n_words': 90}