how to use back button in react native code example

Example 1: go back button react native

import * as React from 'react';
import { Button } from 'react-native';
import { useNavigation } from '@react-navigation/native';

function MyBackButton() {
  const navigation = useNavigation();

  return (
    <Button
      title="Back"
      onPress={() => {
        navigation.goBack();
      }}
    />
  );
}

Example 2: react router native back button

<BackButton />
Connects the global back button on Android and tvOS to the router’s history. On Android, when the initial location is reached, the default back behavior takes over. Just render one somewhere in your app.