react-native-swipeout icon indicating copy to clipboard operation
react-native-swipeout copied to clipboard

onPress called when component mounts

Open dekm opened this issue 7 years ago • 2 comments

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 avatar Oct 31 '17 09:10 dekm

@dekm Try like this: onPress={this.onRemove} But Swipeout override your OnPress function to autoclose. You can bind press action on 'onOpen' prop too.

Unimate avatar Nov 02 '17 06:11 Unimate

<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} >

lukasreusch avatar Nov 12 '17 01:11 lukasreusch