react-native-swipeout
react-native-swipeout copied to clipboard
onPress called when component mounts
I have a component built with Swipeout that is passed a function from the parent. The function in the parent is using a setState and being called when the swipeout component mounts using onPress.
<Swipeout
onPress={this.onRemove()}
left={swipeoutBtns}
autoClose={true}
backgroundColor='white'
buttonWidth={60} >
This is called on mount even without any user interaction.
onRemove = () => {
const { onRemove } = this.props
console.log("REMOVE");
if (onRemove) {
onRemove()
}
}
@dekm
Try like this:
onPress={this.onRemove}
But Swipeout override your OnPress function to autoclose. You can bind press action on 'onOpen' prop too.
<Swipeout
onPress={this.onRemove}
left={swipeoutBtns}
autoClose={true}
backgroundColor='white'
buttonWidth={60} >
OR
<Swipeout
onPress={() => this.onRemove()}
left={swipeoutBtns}
autoClose={true}
backgroundColor='white'
buttonWidth={60} >