1.0.0 • Published 2 years ago

rn-firebase-upload-hook v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

rn-firebase-image-uploader-hook

  • Easily Upload Photos to fire-base with react native firebase library & Expo
  • Hooks to return state of Progress, downloadUrl, success, error, uploading

installation

to install using npm: npm i rn-firebase-image-uploader-hook

to install using yarn yarn add rn-firebase-image-uploader-hook

Usage

import the package import useImageUpload from "rn-firebase-image-uploader-hook"

Example

const Profile = () => {
  const [
    pickImage,
    selectedImage,
    uploadProgress,
    downloadUrl,
    uploading,
    success,
    error,
    reset,
  ] = useImageUpload();

  return (
    <View>
      <Pressable onPress={pickImage}>
        {user.image || downloadUrl ? (
          <Image
            source={{ uri: user.image || downloadUrl }}
            style={{ width: 100, height: 100 }}
          />
        ) : (
        )}
      </Pressable>

      {uploading && <Text>Uploading... {uploadProgress}/100</Text>}
      {success && <Text>Uploaded successfully</Text>}
      {error && <Text>Upload failed</Text>}
    </View>
  );
};

Common Use

When destructing consts from useImageUpload() hook you get

returnTypeDescription
pickImagefunctionasks for permission to view photos from device, and views Image Picker
selectedImageuriuri to the selected image
uploadProgressnumber (1..100)Indicates precentage of upload progress
downloadUrlstringurl of uploaded photo to firebase storage
uploadingBooleanif uploading process is in progress
successBooleanif uploading has finished successfully
errorBooleanif error has occoured
resetmethodresets the state of downloadUrl, selectedImage, uploading, success, error

###End