question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot destructure property 'onGestureHandlerStateChange' of 'this.ref.props' as it is undefined.

See original GitHub issue

This is a bug in react native web. I want to detect double tap using TapGestureHandler. It works perfectly fine in Android and iOS but in Web, I get this error:

TypeError: Cannot destructure property 'onGestureHandlerStateChange' of 'this.ref.props' as it is undefined.
TapGestureHandler.GestureHandler.sendEvent
node_modules/react-native-gesture-handler/web/GestureHandler.js:151
  148 | 
  149 | sendEvent = nativeEvent => {
  150 |   const {
> 151 |     onGestureHandlerStateChange: onHandlerStateChange,
      | ^  152 |     onGestureHandlerEvent: onGestureEvent,
  153 |   } = this.ref.props;
  154 | 

Versions

react-native: 0.62.2 react-native-web: 0.13.6 react-native-gesture-handler: 1.7.0

Sample code to generate issue

// Tapper.tsx
import React from 'react';
import {
  State,
  TapGestureHandler,
  TapGestureHandlerStateChangeEvent,
} from 'react-native-gesture-handler';

type Props = {
  onSingleTap?: () => void;
  onDoubleTap?: () => void;
  children: React.ReactNode;
};

const Component: React.FC<Props> = ({ children, onDoubleTap, onSingleTap }) => {
  const doubleTapRef = React.useRef<TapGestureHandler>();
  const handleSingleHandlerStateChange = React.useCallback(
    (event: TapGestureHandlerStateChangeEvent) => {
      if (event.nativeEvent.state === State.ACTIVE) {
        onSingleTap?.();
      }
    },
    [onSingleTap]
  );

  const handleDoubleHandlerStateChange = React.useCallback(
    (event: TapGestureHandlerStateChangeEvent) => {
      if (event.nativeEvent.state === State.ACTIVE) {
        onDoubleTap?.();
      }
    },
    [onDoubleTap]
  );

  return (
    <TapGestureHandler
      onHandlerStateChange={handleSingleHandlerStateChange}
      waitFor={doubleTapRef}
    >
      <TapGestureHandler
        // @ts-ignore
        ref={doubleTapRef}
        onHandlerStateChange={handleDoubleHandlerStateChange}
        numberOfTaps={2}
      >
        {children}
      </TapGestureHandler>
    </TapGestureHandler>
  );
};

Component.displayName = 'Tapper';

export default Component;

Just use this component with any component in web.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:12
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

16reactions
prft-alex-matticecommented, Aug 31, 2020

Hi, I had investigated this issue for one of our projects and thought I would post my findings. I don’t think we will be able to commit time to posting a PR, but I’ve at least diagnosed the problem. This may be of help to others and the maintainers.

We recently updated a project from React Native Web from 0.12 to 0.13, and then needed to downgrade. In the release notes, it seems that RNW has changed which props it is forwarding through its refs to the DOM. It seems that there are a few places in the react-native-gesture-handler web code where it is accessing these props through the ref.

As a temporary workaround, downgrading to 0.12 stops the crash for the time being, with the caveat that you’re missing compatibility with changes from later RN versions (ex: no Pressable, if I’m not mistaken). Later this week, if it’s deemed helpful, I can try to find the spots in the codebase where these references are at least occurring if it will help speed up the creation of a patch.

11reactions
kwoxercommented, Dec 27, 2020

Ahh sorry, didn’t see that the fix happened in react-native-gesture-handler.

Upgrading to “react-native-gesture-handler”: “~1.9.0”, fixed the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot destructure property 'recipes' of ...
One of your assignments is not properly transferred to a component, that is why it is "Undefined". Upload the parts of the code...
Read more >
Next.js error: Cannot destructure property? : r/learnjavascript
I am following a tutorial and I cannot figure out why Next keeps throwing this error: TypeError: Cannot destructure property 'loginUser' of ...
Read more >
Cannot destructure property 'text' of 'props.message' as it is ...
Coding example for the question TypeError: Cannot destructure property 'text' of 'props.message' as it is undefined-Reactjs.
Read more >
https://ewserver.di.unimi.it/gitlab/public_accessi...
propertyIsEnumerable;function f(t){if(null===t||void 0===t)throw new TypeError('Object.assign cannot be called with null or undefined');return ...
Read more >
https://raw.githubusercontent.com/artem-sedykh/min...
createElement(_Wave.default, { ref: function ref(_ref2) { return _this10. ... if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found