3

The React-Native-Gesture-Handler docs show Swipeable methods implemented in JS classes and only being accessible by the "this" keyword e.g. this.close

Example from docs:

...
<RectButton style={styles.leftAction} onPress={this.close}>
...
 

How do I use the "this" keyword (or its alternative) in React functional components to access these methods?

gts
  • 421
  • 4
  • 7

1 Answers1

1

Use Ref in this case:

const YourComponent = () => {

    const swipeRef = React.useRef()

    const closeSwipable = () => {
        swipeRef?.current?.close()
    }

    return (
        <Swipeable ref={swipeRef}>
        </Swipeable>
    )
}
nodir.dev
  • 414
  • 4
  • 5