Natalie Merrill
Natalie Merrill

Reputation: 157

Function inside renderItem in flatlist

I have a flatlist and it's working fine, I'm trying to put a function inside the code that is rendering my item but it gives me an error, and i need to put the function there so i can read the item's properties, here is my code:

_renderItem ({ item, index}) {
     _shareText() {
          Share.share({
            message: item.name,
          })
        } 
return (
 <Button title="Share" onPress={this._shareText}/>
);
}

Upvotes: 0

Views: 1575

Answers (1)

Brayan Salazar
Brayan Salazar

Reputation: 334

try this, i can see that _shareText is not defined like a function in the component

_shareText(item) {
  Share.share({
    message: item.name,
  })
}

_renderItem({ item, index }) {
  return (
    <Button title="Share" onPress={() => { this._shareText(item); }} />
  );
}

Upvotes: 1

Related Questions