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.

Cannot read property 'bind' of undefined / undefined is not an object evaluating _this._setComponentRef.bind

See original GitHub issue

Environment

React Native Environment Info:

    System:
      OS: macOS High Sierra 10.13.6
      CPU: x64 Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
      Memory: 1.93 GB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 8.11.2 - ~/.nvm/versions/node/v8.11.2/bin/node
      Yarn: 1.12.1 - ~/.nvm/versions/node/v8.11.2/bin/yarn
      npm: 5.6.0 - ~/.nvm/versions/node/v8.11.2/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
    IDEs:
      Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.6.0-alpha.8af6728 => 16.6.0-alpha.8af6728 
      react-native: 0.57.4 => 0.57.4 
    npmGlobalPackages:
      react-native-cli: 2.0.1

Description

With the latest react-native cli (2.0.1) when using TouchableOpacity, the app crash and throws an error: TypeError: Cannot read property ‘bind’ of undefined This error is located at: in AnimatedComponent (at TouchableOpacity.js:256)

Reproducible Demo

Using react-native init, I have added only a simple TouchableOpacity inside the code :

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, TouchableOpacity} from 'react-native';

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
  android:
    'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

export default class App extends Component{
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>Welcome to React Native!</Text>
        <Text style={styles.instructions}>To get started, edit App.js</Text>
        <Text style={styles.instructions}>{instructions}</Text>
        <TouchableOpacity onPress={() => {console.log('touched')}}>
         <Text> Touch Here </Text>
       </TouchableOpacity>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

screen shot 2018-11-05 at 8 01 45 pm

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:9

github_iconTop GitHub Comments

7reactions
xuan9commented, Nov 21, 2018

Workaround by removing the following plugins from .babelrc: [“@babel/plugin-proposal-decorators”, { “legacy”: true }] ,[“@babel/plugin-proposal-class-properties”, { “loose” : true }]

The plugins were used by mobx decorators, now converted to a no-decorator style.

https://mobx.js.org/best/decorators.html

5reactions
pooyakncommented, Nov 17, 2018

I have the exact same problem with new react native project and a touchable opacity component on windows 10. I don’t know how, but the exact same code runs fine on Linux (Opensuse Leap 42.3). Also react navigation throws a similar error. It’s frustrating.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Cannot read property 'bind' of undefined
There is a typo in onClick on button: this.OnShow.bind(this) is the right way. Function is named OnShow, the state var is named onShow....
Read more >
React TypeError: Cannot read property function of undefined
Your browser can't play this video. ... eact TypeError: Cannot read property send_Data_to_Api of undefined solution: bind the function in ...
Read more >
TypeError: Cannot read property 'bind' of undefined
I know I've asked for help before, but I need some again. The title says it all, but is there anything I can...
Read more >
Error: Cannot Read Property setState of Undefined
Inside the constructor, after the state object, input this line: this.handleChange = this.handleChange.bind(this);. This line will bind the “ ...
Read more >
Cannot read property 'bind' of undefined-Reactjs
[Solved]-Uncaught TypeError: Cannot read property 'bind' of undefined-Reactjs. Search. score:0 ... selectItem.bind(this, item.id) becomes this.props.
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