0

How can I bind a function to handle a View component event using it's reference inside an useEffect in React Native? I tried a few things (see below code) and they all return viewRef.current.something is undefined. I logged the entire current object and looked through it extensively and found nothing.

export default function App() {
  const viewRef = useRef();

  useEffect(() => {
    if (viewRef && viewRef.current) {
      //viewRef.current.addEventListener is undefiend
      viewRef.current.addEventListener("onTouchEnd", (e) => {
        //do something
      });
      //viewRef.current.onTouchEnd is undefiend
      viewRef.current.onTouchEnd((e) =>{
        //do something
      })
    }
  }, [viewRef]);

  return (
    <View ref={viewRef} style={styles.container}>
      <DummyComponent />
    </View>
  );
}
Pelicer
  • 1,348
  • 4
  • 23
  • 54

0 Answers0