8000 [useClickAway] 支持传入事件监听选项 · Issue #2770 · alibaba/hooks · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[useClickAway] 支持传入事件监听选项 #2770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
9831
Xav1erSue opened this issue Apr 29, 2025 · 0 comments
Open

[useClickAway] 支持传入事件监听选项 #2770

Xav1erSue opened this issue Apr 29, 2025 · 0 comments

Comments

@Xav1erSue
Copy link

背景:如果有元素的点击事件中阻止了冒泡,会导致 useClickAway 无法捕捉到此次点击

代码:

import React, { useState, useRef } from "react";
import { useClickAway } from "ahooks";

export default () => {
  const [counter, setCounter] = useState(0);

  const ref = useRef<HTMLButtonElement>(null);

  useClickAway(() => setCounter((s) => s + 1), ref);

  return (
    <div>
      <button ref={ref} type="button">
        box1
      </button>
      <button
        type="button"
        style={{ marginLeft: 16 }}
        onClick={(e) => e.stopPropagation()}
      >
        box2
      </button>
      <p>counter: {counter}</p>
    </div>
  );
};

期望:支持传入事件监听选项如 capture 等参数,改变事件捕获时机

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0