dancormier / react-native-swipeout

iOS-style swipeout buttons behind component
MIT License
2.62k stars 649 forks source link

Is there any way to implement onPress without an arrow function within render()? #228

Closed lukewlms closed 7 years ago

lukewlms commented 7 years ago

All examples I've seen for implementing onPress on a swipeout button involve creating an arrow function inside of render().

For example, from this blog post (Aug 2017) defines swipeSettings inside of renderItem.

As far as I know, arrow functions are discouraged inside of render() because of performance - a new function instance is created on every render.

Can we use this library without also creating arrow functions inside of render()? So far I don't see another way for onPress to know what data it's for. (It seems natural that it would take a sectionId and rowId as onOpen do, but somehow it does not.)

silentcloud commented 7 years ago

@lukecwilliams

like this ?

left = [{
  text: 'More',
  onPress() { console.log('more press') },
}]
lukewlms commented 7 years ago

that looks like it will work if we don't need to use this.

I think the more general solution is to extract the item into its own component, so that it can just render with its props. Thanks for the response!