loading...
Cover image for Share files on React Native

Share files on React Native

gabrielrufino profile image Gabriel Rufino ・1 min read

File sharing is a very common feature in many apps. For this purpose on React Native, we can use the lib React Native Share.

Install React Native Share

$ npm install react-native-share --save

One more step for iOS

$ npx pod-install
# or
$ cd ios && pod install

Share a file

import React, {useCallback} from 'react';
import {View, Button} from 'react-native';
import Share from 'react-native-share';

export default function ShareAudio () {
  const onShareAudio = useCallback(function () {
    Share.open({
      url: `file:///data/data/com.yourapp/files/audio.mp3`,
      type: 'audio/mp3',
    });
  }, []);

  return (
    <View>
      <Button
        title="Share audio"
        onPress={onShareAudio}
      />
    </View>
  );
};

Discussion

markdown guide