{"id":26121867,"url":"https://github.com/ipfs-shipyard/react-ipfs-url","last_synced_at":"2025-04-13T13:06:05.102Z","repository":{"id":34944257,"uuid":"193023901","full_name":"ipfs-shipyard/react-ipfs-url","owner":"ipfs-shipyard","description":"Grab a URL from a IPFS path by using URL.createObjectURL","archived":false,"fork":false,"pushed_at":"2023-01-04T00:50:46.000Z","size":1649,"stargazers_count":12,"open_issues_count":22,"forks_count":2,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-13T13:05:57.974Z","etag":null,"topics":["create-object-url","infura","ipfs","react","url"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ipfs-shipyard.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-21T03:25:35.000Z","updated_at":"2024-05-30T11:31:58.000Z","dependencies_parsed_at":"2023-01-15T10:51:18.146Z","dependency_job_id":null,"html_url":"https://github.com/ipfs-shipyard/react-ipfs-url","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-shipyard%2Freact-ipfs-url","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-shipyard%2Freact-ipfs-url/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-shipyard%2Freact-ipfs-url/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-shipyard%2Freact-ipfs-url/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ipfs-shipyard","download_url":"https://codeload.github.com/ipfs-shipyard/react-ipfs-url/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717242,"owners_count":21150389,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["create-object-url","infura","ipfs","react","url"],"created_at":"2025-03-10T14:37:05.465Z","updated_at":"2025-04-13T13:06:05.081Z","avatar_url":"https://github.com/ipfs-shipyard.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-ipfs-url\n\n[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][codecov-image]][codecov-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url]\n\n[npm-url]:https://npmjs.org/package/react-ipfs-url\n[downloads-image]:http://img.shields.io/npm/dm/react-ipfs-url.svg\n[npm-image]:http://img.shields.io/npm/v/react-ipfs-url.svg\n[travis-url]:https://travis-ci.org/ipfs-shipyard/react-ipfs-url\n[travis-image]:http://img.shields.io/travis/ipfs-shipyard/react-ipfs-url/master.svg\n[codecov-url]:https://codecov.io/gh/ipfs-shipyard/react-ipfs-url\n[codecov-image]:https://img.shields.io/codecov/c/github/ipfs-shipyard/react-ipfs-url/master.svg\n[david-dm-url]:https://david-dm.org/ipfs-shipyard/react-ipfs-url\n[david-dm-image]:https://img.shields.io/david/ipfs-shipyard/react-ipfs-url.svg\n[david-dm-dev-url]:https://david-dm.org/ipfs-shipyard/react-ipfs-url?type=dev\n[david-dm-dev-image]:https://img.shields.io/david/dev/ipfs-shipyard/react-ipfs-url.svg\n\nGrab a URL from a IPFS path by using [`URL.createObjectURL`](https://developer.mozilla.org/en-US/docs/Web/API/URL/createObjectURL).\n\n\n## Installation\n\n```sh\n$ npm install react-ipfs-url\n```\n\nThis library is written in modern JavaScript and is published in both CommonJS and ES module transpiled variants. If you target older browsers please make sure to transpile accordingly.\n\n\n## Usage\n\n**With `\u003cIpfsUrl\u003e` component**:\n\n```js\nimport React from 'react';\nimport { IpfsUrl } from 'react-ipfs-url';\n\nconst ipfs = /* your ipfs node, perhaps provide it via context */;\n\nconst SomeComponent = () =\u003e (\n    \u003cIpfsUrl ipfs={ ipfs } input=\"/ipfs/QmQuMzeovz...\"\u003e\n        { ({ status, value }) =\u003e (\n            \u003c\u003e\n                { status === 'pending' \u0026\u0026 'Loading...' }\n                { status === 'rejected' \u0026\u0026 'Oops, failed to load' }\n                { status === 'fulfilled' \u0026\u0026 \u003cimg src={ value } alt=\"\" /\u003e }\n            \u003c\u003e\n        ) }\n    \u003c/IpfsUrl\u003e\n);\n```\n\n**With `useIpfsUrl()` hook**:\n\n```js\nimport React from 'react';\nimport { useIpfsUrl } from 'react-ipfs-url';\n\nconst ipfs = /* your ipfs node, perhaps provide it via context */;\n\nconst SomeComponent = () =\u003e {\n    const [urlStatus, urlValue] = useIpfsUrl(ipfs, '/ipfs/QmQuMzeovz..');\n\n    return (\n        \u003c\u003e\n            { status === 'pending' \u0026\u0026 'Loading...' }\n            { status === 'rejected' \u0026\u0026 'Oops, failed to load' }\n            { status === 'fulfilled' \u0026\u0026 \u003cimg src={ value } alt=\"\" /\u003e }\n        \u003c/\u003e\n    );\n};\n```\n\n## API\n\n- [`\u003cIpfsUrl\u003e`](#ipfsurl)\n- [`useIpfsUrl(ipfs, input, [options])`](#useipfsurlipfs-input-options)\n\n### IpfsUrl\n\nThe `\u003cIpfsUrl\u003e` component allows you to conditionally render children based on the url status and fulfillment/rejection value. It leverages the [render props](https://reactjs.org/docs/render-props.html) technique to know what to render.\n\n#### Props\n\nAll properties from [react-promiseful](https://github.com/moxystudio/react-promiseful) are also valid.\n\n##### ipfs\n\nType: `object`\n\nThe [ipfs](https://github.com/ipfs/js-ipfs) node to be used.\n\n##### input\n\nType: `string`\n\nA valid IPFS path, hash or a provider URL, such as a gateway URL or an Infura URL.\n\n\u003e ⚠️ At the moment, IPNS paths are not supported for the `ipfs` and `ipfsOffline` providers: https://github.com/ipfs-shipyard/react-ipfs-url/issues/2\n\n\u003e ⚠️ There's no support for fully qualified domains URLs yet: https://github.com/ipfs-shipyard/react-ipfs-url/issues/4\n\n##### strategy\n\nType: `string`   \nDefault: `input-first`\n\nThe strategy to use when resolving a valid URL.\n\n- `input-first`: Use the provider associated with the `input` first and fallback to resolving with IPFS.\n- `ipfs-first`: Use IPFS to resolve the URL first and fallback to resolving with the provider associated with the `input`\n- `ipfs-offline-first`: Use offline IPFS first and fallback to resolving with the provider, followed by the online IPFS.\n- `ipfs-only`: Only use IPFS to resolve the URL, even if `input` comes from another provider\n- `ipfs-offline-only`: Only use IPFS (offline) to resolve the URL, even if `input` comes from another provider\n\n##### checkTimeout\n\nType: `object`   \nDefault: `{ gateway: 12500, infura: 12500, ipfsOffline: 5000, ipfs: 180000 }`\n\nThe max time to spend checking for the existence of the content on providers.\n\n##### disposeDelayMs\n\nType: `number`   \nDefault: 60000\n\nThe delay in which object urls created with `URL.createObjectURL` are revoked when they are no longer used.\n\n##### children\n\nType: `Function`\n\nA render prop function with the following signature:\n\n```js\n(state) =\u003e {}\n```\n\nThe `state` argument is an object that contains the following properties:\n\n- `status` is one of `none` (when there's no promise), `pending`, `rejected`, `fulfilled`\n- `value` is either the fulfillment value (url) or the rejection value\n- `withinThreshold` indicating if we are still within the configured [`thresholdMs`](https://github.com/moxystudio/react-promiseful#thresholdms)\n\nSee [react-promiseful](https://github.com/moxystudio/react-promiseful) for more info.\n\n\n### useIpfsUrl(ipfs, input, [options])\n\nThe hook version of the `\u003cIpfsUrl\u003e` component. The `options` available to both are exactly the same.\n\n```js\nconst urlState = useIpfsUrl(ipfs, '/ipfs/QmQuMzeovz..');\n```\n\nThe returned value from the hook is the url promise state, an object that contains the following properties:\n\n- `status` is one of `none` (when there's no promise), `pending`, `rejected`, `fulfilled`\n- `value` is either the fulfillment value (url) or the rejection value\n- `withinThreshold` indicating if we are still within the configured [`thresholdMs`](https://github.com/moxystudio/react-promiseful#thresholdms)\n\nSee [react-promiseful](https://github.com/moxystudio/react-promiseful) for more info.\n\n\n## Tests\n\n```sh\n$ npm test\n$ npm test -- --watch # during development\n```\n\n\n## License\n\nReleased under the [MIT License](http://www.opensource.org/licenses/mit-license.php).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipfs-shipyard%2Freact-ipfs-url","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fipfs-shipyard%2Freact-ipfs-url","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipfs-shipyard%2Freact-ipfs-url/lists"}