React hooks for the hypercore-protocol stack
npm i use-hyper
Warning: this is experimental, and API might change until v1.
Every hook requires the related library installed:
useCore
depends onhypercore
.useDHT
depends on@hyperswarm/dht-relay
.useSwarm
depends onhyperswarm
.
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.
MIT