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.

I get `_this4.myfunc is not a function` calling this.myfunc() from onPress() of a TouchableHighlight in an item

See original GitHub issue

I’ve got a carousel like this:

  render() {
    <Carousel
      ref={(carousel) => { this._carousel = carousel; }}
      renderItem={this._renderCarouselItem}
      data={this.state.person.imagesList}
      sliderWidth={this.state.viewport.width}
      itemWidth={this.state.viewport.width}
    >
    </Carousel>
  }

  _renderCarouselItem({item, index}) {
    return (
      <TouchableHighlight key={item.key} onPress={() => this.setFullscreen(item.key)}>
        <Image
          source={{uri: item.uri}}
        />
      </TouchableHighlight>
    );
  }

  setFullscreen(index) {
    ...
  }

The problem is I don’t know how to bind to this in _renderCarouselItem function, since when pressing on an image I get a reddish _this4.setFullscreen is not a function… Any clue?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
bd-arccommented, Aug 25, 2017

@marcolino Did you make sure to bind this to your function in your constructor? Something along those lines:

    constructor (props) {
        super(props);
        this.setFullscreen = this.setFullscreen.bind(this);
    }
0reactions
fliptechkumarcommented, Jun 21, 2018

Thanks @NicholasBertazzon its working for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

I get _this4.myfunc is not a function calling this ... - GitHub
I get _this4.myfunc is not a function calling this.myfunc() from onPress() of a TouchableHighlight in an item #130.
Read more >
TouchableHighlight OnPress is not calling a function
I'm making an app in React Native and i have a problem that i don't understand.
Read more >
TouchableHighlight - React Native
A wrapper for making views respond properly to touches. On press down, the opacity of the wrapped view is decreased, which allows the ......
Read more >
Error: Undefined is not a function : r/reactnative - Reddit
For some reason, when I press my AddButton, I get the error "Undefined is not a function, evaluating "this.setModalVisible(true)".
Read more >
What is the TouchableHighlight in react native - GeeksforGeeks
TouchableHighlight is a component that is used to provide a wrapper to Views in order to make them respond correctly to touch-based input....
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