Do not work, If we pass element as ref
See original GitHub issueIf we pass element ref as below
const counterEl = useRef(null);
useEventListener('click', () => alert('Ref click'), counterEl);
return (
<div className="App">
Count: <span ref={counterEl}>{count}</span>
<button onClick={increment}>+</button>
</div>
);
But, It will work If we pass elementRef.current as below
useEventListener('click', () => alert('Ref click'), counterEl.current);
Will suggest a change, and If you allow will create a PR with the following change
const targetIsRef = element.hasOwnProperty('current');
const currentTarget = targetIsRef ? element.current : element;
const isSupported = currentTarget && currentTarget.addEventListener;
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Are you allowed to assign an element a ref if the parent ...
I am working on existing code (ReusableComponent) so changing all instances of ReusableComponent to pass a ref is not viable.
Read more >Refs and the DOM - React
Refs are commonly assigned to an instance property when a component is constructed so they can be referenced throughout the component.
Read more >A complete guide to React refs - LogRocket Blog
Learn how to use React refs, and why it's important to use them only when React can't handle a function call through its...
Read more >Everything You Need to Know About Refs in React
New and experienced developers alike seem to have trouble with the Refs API. Learn why, how, and when to use Refs in your...
Read more >Avoiding useEffect with callback refs - TkDodo's blog
Luckily, React uses referential stability to check if the callback ref should be run or not. That means if we pass the same...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any progress on this?
check #40