npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-ipfs-components

v0.1.6

Published

React components for fetch and display IPFS content using public gateways.

Downloads

24

Readme

Load any IPFS content from the fastest gateway available just passing a valid path.

React IPFS Components is a powerful library of React components that allows you to easily load any InterPlanetary File System (IPFS) content from the fastest gateway available. With this library, you no longer need to worry about configuring or setting up any gateways or passing a correct CID as a parameter. The plugin itself automatically verifies the fastest suitable gateways from the Public Gateways list provided by Protocol Labs.

Once you have successfully connected to at least three of these gateways, the content will show up automatically. The service to fetch images and JSON (metadata) files works by decoupling the URL/CID/Path passed and checking if it is a valid IPFS link. In case of a successful fetch for the CID and subpaths, it uses the best gateway possible to fetch content. If it successfully fetches from one of the best gateways, it returns immediately. Otherwise, it will fallback to the URL previously passed.

If the component fails to fetch data from the gateways multiple times, that source will be removed from the list and another one will take its place. This ensures that you always get the fastest and most reliable connection possible.

Live Demo / Live Demo Repo

Sources for media supported includes:

  • [x] Path with CIDv0 only: Qm...
  • [x] Path with CIDv1 only: bafy...
  • [x] IPFS protocol path: ipfs://...
  • [x] Pre-filled IPFS gateway path: https://ipfs.io/ipfs/...
  • [x] CIDv1 with subdomain path: https://bafy.../2.png
  • [x] Non IPFS URLs (Will fetch url itself.)

Installation

First install package on your project:

npm install -s react-ipfs-components

Second initalize the fetcher on your main.jsx file:

import {IPFSFetcher} from 'react-ipfs-components'

IPFSFetcher.Initialize();

Then you can import components and use them on your jsx files:

import { IPFSAvatar, IPFSImage, IPFSVideo, IPFSFetcher } from 'react-ipfs-components'

Usage

We feature two different components with preload:

IPFSAvatar: A component that has two different properties.

  • size: The size of the image in pixels.
  • radius: The border radius of the image.
<IPFSAvatar size="20" radius="20" src="path or cid"/>
<IPFSAvatar size="100" radius="0" src="path or cid"/>

IPFSImage: A component that has two different properties.

  • width: The width of the image in pixels.
  • height: The height of the image in pixels.
<IPFSImage width="20" height="20" src="path or cid"/>
<IPFSImage width="100" height="300" src="path or cid"/>

IPFSVideo: A video component with multiple options.

  • width: The width of the image in pixels.
  • height: The height of the image in pixels.
  • controls: Show navigation controls.
  • muted: Mute the video.
  • loop: Restart video automatically once finished.
  • autoplay: Play video automatically after loaded.
<IPFSVideo width="320" height="240" src="path or cid"/>

Both the IPFSImage, IPFSVideo and IPFSAvatar components extend a third component called ipfs-media. This component is responsible for communication with the component core, while the other two components handle how the object will be displayed. If you want to customize an implementation, you can extend ipfs-media the same way ipfs-squared and ipfs-avatar do with the desired modifications. This allows you to have full control over how the media is displayed while still benefiting from the underlying functionality provided by the React IPFS Components library.

References:

  • IPFS Public Fetcher Library - Repo

  • Protocol-Labs public gateway list: Website / Repo