backHandler.ts

mail@pastecode.io avatar
unknown
plain_text
a month ago
466 B
1
Indexable
Never
import { useEffect } from 'react';
import { BackHandler } from 'react-native';

const useHardwareBackButton = (callback) => {
  useEffect(() => {
    const backAction = () => {
      if (callback) {
        return callback();
      }
      return true;
    };

    const backHandler = BackHandler.addEventListener(
      'hardwareBackPress',
      backAction
    );

    return () => backHandler.remove();
  }, [callback]);
};

export default useHardwareBackButton;
Leave a Comment