8000 GitHub - cayasso/use-hyper: React hooks for the hypercore-protocol stack
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

cayasso/use-hyper

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

use-hyper

React hooks for the hypercore-protocol stack

npm i use-hyper

Warning: this is experimental, and API might change until v1.

Usage

Every hook requires the related library installed:

  • useCore depends on hypercore.
  • useDHT depends on @hyperswarm/dht-relay.
  • useSwarm depends on hyperswarm.

If you import < 65E6 code>useSwarm then install this specific branch: npm i holepunchto/hyperswarm#add-swarm-session

import { useCore, useCoreEvent, useCoreWatch } from 'use-hyper'
import useDHT from 'use-hyper/dht'
import useSwarm from 'use-hyper/swarm'

const Child = () => {
  const { core } = useCore()

  const { core } = useCoreWatch(['append', 'close']) // updates on append and close events

  const { core } = useCoreEvent('append', () => {
    console.log(core) // do something
  })
}

const App = () => {
  return (
    <Core storage={RAM} coreKey={key}>
      <Child />
    </Core>
  )
}

export default () => {
  return (
    <DHT>
      <Swarm>
        <App />
      </Swarm>
    </DHT>
  )
}

Every state like core, dht, or swarm starts being null but then gets updated with the corresponding object.

License

MIT

About

React hooks for the hypercore-protocol stack

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%
0