What is the TypeScript definition for the onTouchStartCapture event in React?

The right interface for onTouchStartCapture is TouchEvent

Please continue reading below to see how to use it or read my guide on using React events with TypeScript.

You can also go to the search page 🔍 to find another event.

Interface

interface TouchEvent<T = Element> extends UIEvent<T, NativeTouchEvent> {
    altKey: boolean;
    changedTouches: TouchList;
    ctrlKey: boolean;
    /**
     * See [DOM Level 3 Events spec](https://www.w3.org/TR/uievents-key/#keys-modifier). for a list of valid (case-sensitive) arguments to this method.
     */
    getModifierState(key: string): boolean;
    metaKey: boolean;
    shiftKey: boolean;
    targetTouches: TouchList;
    touches: TouchList;
}

Full example

import React, { TouchEvent } from 'react';

const ButtonComponent = () => {
  const handleTouchEvent = (e: TouchEvent<HTMLButtonElement>) => {
    e.preventDefault();
    // Do something
  };

  return <button onTouchStartCapture={handleTouchEvent}>Click me!</button>;
};

export default ButtonComponent;

Attributes that use TouchEvent:

Get notified about new tutorials

Join over 1,000 developers who receive React and JavaScript tutorials via email.

No spam. Unsubscribe at any time.