{"id":21244088,"url":"https://github.com/aaronksaunders/react-custom-fb-upload-hooks","last_synced_at":"2026-04-16T12:02:26.675Z","repository":{"id":39308787,"uuid":"224560543","full_name":"aaronksaunders/react-custom-fb-upload-hooks","owner":"aaronksaunders","description":"sample application for ionic react js custom hook for file upload to firebase storage","archived":false,"fork":false,"pushed_at":"2023-01-04T13:22:11.000Z","size":975,"stargazers_count":2,"open_issues_count":25,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-15T04:26:35.344Z","etag":null,"topics":["file-upload","firebase","firebase-authentication","firebase-storage","ionic-framework","javascript","react-hooks","reactjs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aaronksaunders.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-28T03:13:07.000Z","updated_at":"2020-03-03T04:55:48.000Z","dependencies_parsed_at":"2023-02-02T13:45:50.715Z","dependency_job_id":null,"html_url":"https://github.com/aaronksaunders/react-custom-fb-upload-hooks","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aaronksaunders/react-custom-fb-upload-hooks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronksaunders%2Freact-custom-fb-upload-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronksaunders%2Freact-custom-fb-upload-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronksaunders%2Freact-custom-fb-upload-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronksaunders%2Freact-custom-fb-upload-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aaronksaunders","download_url":"https://codeload.github.com/aaronksaunders/react-custom-fb-upload-hooks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronksaunders%2Freact-custom-fb-upload-hooks/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31884929,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T11:36:10.202Z","status":"ssl_error","status_checked_at":"2026-04-16T11:36:09.652Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["file-upload","firebase","firebase-authentication","firebase-storage","ionic-framework","javascript","react-hooks","reactjs"],"created_at":"2024-11-21T01:15:49.932Z","updated_at":"2026-04-16T12:02:26.654Z","avatar_url":"https://github.com/aaronksaunders.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Ionic: ReactJS Custom Firebase Storage Hook\n\nThis project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).\n\nSample app integrating firebase with a react application using react hooks api and [React Firebase Hooks](https://github.com/CSFrequency/react-firebase-hooks) - A set of reusable [react hooks](https://reactjs.org/docs/hooks-intro.html) for [Firebase](https://firebase.google.com/docs/web/setup?authuser=0).\n\n**We also have built our own custom firebase storage file upload hook**, [jump directly to source code](https://github.com/aaronksaunders/react-custom-fb-upload-hooks/blob/master/src/hooks/use-firebase-upload.js)\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"./custom hook 1.png\"  width='40%'\u003e\n\u003cimg src=\"./custom hook 2.png\"  width='40%'\u003e\n\u003c/p\u003e\n\n## Getting A Collecting of Things\n\nThis is from firebase-hooks, it allows us to query all of the item from the `things` collection in the database in descending order based on the creation data. the `value` will containg the results of the query that we will loop through to render the list items\n\n```javascript\nconst [value, loading, error] = useCollection(\n  firebase\n    .firestore()\n    .collection(\"image-file\")\n    .orderBy(\"createdOn\", \"desc\"),\n  {\n    snapshotListenOptions: { includeMetadataChanges: true }\n  }\n);\n```\n\n## Adding a Specific Thing\n\nWhen saving the thing, determine if it is a new object or an existing object by checking to see if there was an `initialValue` provided as a property. If there was, then we have an object id so we need to update the object and not create a new object\n\n```javascript\n/**\n * on save determine if it is a new object or an existing object\n * by check to see if there was an initial value provided\n */\nconst onSave = async () =\u003e {\n  let collectionRef = firebase.firestore().collection(\"image-file\");\n\n    await collectionRef.add({ name: thing, createdOn: new Date().getTime() });\n    setThing(\"\");\n    clear();\n};\n```\n\n## Uploading a File to Firebase Storage\n- [See Code](https://github.com/aaronksaunders/react-custom-fb-upload-hooks/blob/master/src/hooks/use-firebase-upload.js)\n- **working on more detailed blog post**\n\n## Deleting A Specific Thing\n\nThere is no firebase-hook to delete an object, we just used the firebase javascript api to remove the object\n\nyou need to remove the object from firebase storage first...\n\n```javascript\n// reference is stored of document that will be deleted next\n  const storageRef = firebase.storage().ref().child(ref);\n  await storageRef.delete();\n```\n\n```javascript\n/**\n * deletes item from firebase database using the id\n * of the object\n */\n  let result = await firebase.firestore()\n    .collection(\"image-file\")\n    .doc(id)\n    .delete();\n};\n```\n\n\n## Setting Up For Capacitor\n\n### Using Capacitor Camera Plugin\nI used the Camera Plugin to address issues I was running into related to orientation when running the application on my iOS device. \n\n```javascript\nimport { defineCustomElements } from '@ionic/pwa-elements/loader';\n```\nThen later in the startup process you will need to call\n```javascript\ndefineCustomElements(window);\n```    \nSee `App.js` for additional details.\n\n\u003eKnown issue with file input - https://github.com/ionic-team/capacitor/pull/1856\n\n### Add Capacitor (https://capacitor.ionicframework.com) to Project:\n\n```\nnpm install --save @capacitor/core @capacitor/cli\n```\nOR\n```\nyarn add  @capacitor/core @capacitor/cli\n```\n\n### Package up app for build:\n\n```\nnpm run build\n```\nOR\n```\nyarn run build\n```\n\n### Initialize Capacitor with your app information.\n\n```\nnpx cap init --web-dir=build\n```\n\n\u003e you will be asked the following questions:\n\n```\nCreate app name\nCreate app Package ID (com.example.app)\n```\n\n\u003e In some instances of iOS you will be required to do an additional install\n\nOPTIONAL: install CocoaPods if not already installed (CocoaPods manages library dependencies for your Xcode projects):\n\n```\nsudo gem install cocoapods\n```\n\n### Install the desired native platform:\n\n```console\nnpx cap add android\nnpx cap add ios\nnpx cap add electron\n```\n\n### Sync the platform specific code\n\n```\nnpx cap sync iOS\nnpx cap open iOS (or Android) -\u003e this should open up Xcode or Android Studio\n```\n\n## Deal with safe area, ie the notch on some of the newer devices\n\n```html\n\u003cmeta\n  name=\"viewport\"\n  content=\"width=device-width, initial-scale=1, viewport-fit=cover\"\n/\u003e\n```\n\nAnd set the css for the body\n\n```css\nbody  {\n    padding: env(safe-area-inset-top,  20px)  env(safe-area-inset-right,  20px)\n        env(safe-area-inset-bottom,  20px)  env(safe-area-inset-left,  20px);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronksaunders%2Freact-custom-fb-upload-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faaronksaunders%2Freact-custom-fb-upload-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronksaunders%2Freact-custom-fb-upload-hooks/lists"}