import { Alert, Share } from "react-native";

export function useShare({ messageText }: { messageText: string }) {
  const onShare = async () => {
    try {
      const result = await Share.share({
        message: messageText,
      });
      if (result.action === Share.sharedAction) {
        if (result.activityType) {
          // shared with activity type of result.activityType
        } else {
          // shared
        }
      } else if (result.action === Share.dismissedAction) {
        // dismissed
      }
    } catch (error: any) {
      Alert.alert(error.message);
    }
  };

  return onShare;
}
