在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:ipfs-shipyard/react-ipfs-url开源软件地址:https://github.com/ipfs-shipyard/react-ipfs-url开源编程语言:JavaScript 100.0%开源软件介绍:react-ipfs-urlGrab a URL from a IPFS path by using Installation$ npm install react-ipfs-url This 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. UsageWith import React from 'react';
import { IpfsUrl } from 'react-ipfs-url';
const ipfs = /* your ipfs node, perhaps provide it via context */;
const SomeComponent = () => (
<IpfsUrl ipfs={ ipfs } input="/ipfs/QmQuMzeovz...">
{ ({ status, value }) => (
<>
{ status === 'pending' && 'Loading...' }
{ status === 'rejected' && 'Oops, failed to load' }
{ status === 'fulfilled' && <img src={ value } alt="" /> }
<>
) }
</IpfsUrl>
); With import React from 'react';
import { useIpfsUrl } from 'react-ipfs-url';
const ipfs = /* your ipfs node, perhaps provide it via context */;
const SomeComponent = () => {
const [urlStatus, urlValue] = useIpfsUrl(ipfs, '/ipfs/QmQuMzeovz..');
return (
<>
{ status === 'pending' && 'Loading...' }
{ status === 'rejected' && 'Oops, failed to load' }
{ status === 'fulfilled' && <img src={ value } alt="" /> }
</>
);
}; APIIpfsUrlThe PropsAll properties from react-promiseful are also valid. ipfsType: The ipfs node to be used. inputType: A valid IPFS path, hash or a provider URL, such as a gateway URL or an Infura URL.
strategyType: The strategy to use when resolving a valid URL.
checkTimeoutType: The max time to spend checking for the existence of the content on providers. disposeDelayMsType: The delay in which object urls created with childrenType: A render prop function with the following signature: (state) => {} The
See react-promiseful for more info. useIpfsUrl(ipfs, input, [options])The hook version of the const urlState = useIpfsUrl(ipfs, '/ipfs/QmQuMzeovz..'); The returned value from the hook is the url promise state, an object that contains the following properties:
See react-promiseful for more info. Tests$ npm test
$ npm test -- --watch # during development LicenseReleased under the MIT License. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论