Function useEventListener

  • Never call addEventListener again, just let this hook handle it

    Example

    const MyComponent = () => {
    useEventListener({
    eventName: "keydown",
    listener: event => console.log(event.key),
    });

    return <div />;
    }

    Type Parameters

    • EventName extends string | number | symbol

    • Event

    • Target extends Window | HTMLElement | MediaQueryList = Window

    Parameters

    • __namedParameters: {
          active?: boolean;
          eventName: EventName;
          listener: ((event) => void);
          passive?: boolean;
          target?: Target;
      }
      • Optional active?: boolean
      • eventName: EventName
      • listener: ((event) => void)
          • (event): void
          • Parameters

            • event: Event

            Returns void

      • Optional passive?: boolean
      • Optional target?: Target

    Returns void

Generated using TypeDoc