React Hooks
A collection of React hooks to use with Pinata
Included with the Pinata SDK is the pinata/react
package which comes with a hook you can use to upload files and a convert helper function for converting CIDs into IPFS Gateway URLs.
Installation
Install the Pinata SDK
Usage
Import at the top of your desired page or component
Inside your page or component use the hook to extract methods and state
Keep in mind that states like pause
, resume
, or progress
are only available on files over 100MB that automatically engage resumable uploads through TUS.
Return types for useUpload
To upload a file you must already have a server setup that returns a Presigned URL. Then you can pass it into the upload
method like so.
Below are the available UploadOptions
that can be passed into upload
Once a file is uploaded the uploadResponse
will contain either the full upload response or just the CID if your file was over 100MB and utilized TUS resumable uploads.
The convert
helper can be used to turn a CID into a URL like so:
Below is a full example of implementing the useUpload
hook with progress and abilities to pause and resume the upload.
Questions
Please contact us if you have any issues!