Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
42 lines (33 sloc)
999 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useState, useEffect } from 'react' | |
| import { create } from 'ipfs-core' | |
| const IpfsComponent = () => { | |
| const [id, setId] = useState(null); | |
| const [ipfs, setIpfs] = useState(null); | |
| const [version, setVersion] = useState(null); | |
| const [isOnline, setIsOnline] = useState(false); | |
| useEffect(() => { | |
| const init = async () => { | |
| if (ipfs) return | |
| const node = await create(); | |
| const nodeId = await node.id(); | |
| const nodeVersion = await node.version(); | |
| const nodeIsOnline = node.isOnline(); | |
| setIpfs(node); | |
| setId(nodeId.id); | |
| setVersion(nodeVersion.version); | |
| setIsOnline(nodeIsOnline); | |
| } | |
| init() | |
| }, [ipfs]); | |
| if (!ipfs || !id) { | |
| return <h4>Connecting to IPFS...</h4> | |
| } | |
| return ( | |
| <div> | |
| <h4 data-test="id">ID: {id.toString()}</h4> | |
| <h4 data-test="version">Version: {version}</h4> | |
| <h4 data-test="status">Status: {isOnline ? 'Online' : 'Offline'}</h4> | |
| </div> | |
| ) | |
| } | |
| export default IpfsComponent |