Skip to content

Do not work, If we pass element as ref #35

@prathameshmhatre

Description

@prathameshmhatre

If 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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions