
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
react-holochain-hook
Advanced tools
Provides React apps with easy access to Holochain using the useHolochain() hook
Provides React apps with easy access to Holochain using the useHolochain()
hook.
Encapsulates hc-web-client in a React Context, provides sensible connection status information, some automation and a few convenience functions. ♓️ 🦄🌈
Install it with yarn:
yarn add react-holochain-hook
Or with npm:
npm i react-holochain-hook --save
import {
ProvideHolochain,
useHolochain,
CONNECTION_STATUS
} from 'react-holochain-hook'
const Connected = () => {
const hc = useHolochain()
if (hc.status === CONNECTION_STATUS.CONNECTED) {
return <div>✅ Connected</div>
}
return null
}
function App() {
return (
<div className="App">
<ProvideHolochain options={{ url: 'ws://localhost:10003' }}>
<Connected />
</ProvideHolochain>
</div>
);
}
import { useEffect, useState } from 'react'
const CronutCounting = () => {
const hc = useHolochain()
const [cronutCount, setCronutCount] = useState(0)
useEffect(() => {
if (hc.status === CONNECTION_STATUS.CONNECTED) {
try {
hc.connection.callZome(
'instance_id',
'my_cronut_zome',
'count_cronuts')()
.then((result) => {
const obj = JSON.parse(result)
if (obj.Ok) {
setCronutCount(obj.Ok)
}
})
} catch (err) {
console.log("Unable to count cronuts.")
}
}
}, [hc.connection, hc.status,])
return <div>{cronutCount} cronuts counted. 🍩🍩</div>
}
Encapsulates hc-web-client using a React Context, making holochain connection available throughout the application.
Auto connects to Holochain when application starts.
process.env.NODE_ENV === 'development'
):ws://localhost:3401
.process.env.REACT_APP_WSPORT
options
prop./_dna_connections.json
options
prop.Props:
options
{Object}: (OPTIONAL) Client options that are also forwarded to hc-web-client
and rpc-websockets
.
url
{String}: Websocket url to access Holochain.timeout
{Number}: Connection timeout in milliseconds. Defaults to 5000
.wsClient
{Object}: Client options that are also forwarded to ws
.
autoconnect
{Boolean}: Client autoconnect upon Client class instantiation. Defaults to true
.reconnect
{Boolean}: Whether client should reconnect automatically once the connection is down. Defaults to true
.reconnect_interval
{Number}: Time between adjacent reconnects. Defaults to 2000
.max_reconnects
{Number}: Maximum number of times the client should try to reconnect. Defaults to 5
. 0
means unlimited.Gives access to holochain connection, connection status, etc.
Returns object containing:
options
{Object}: Options for current connection (READ ONLY)connect
{Function}: Connect manually to Holochain using the same options as described for ProvideHolochain
. Use only when status
is NOT_CONNECTED
or CONNECT_FAILED
.connection
{Any}: Exposes the underlying hc-web-client
connection object with the call
, and callZome
functions. See hc-web-client for details.status
{Number}: Connection status using the values specified by CONNECTION_STATUS
setMeta(key, value)
{Function}: Convenience funtion to save connection related metadata during the lifespan of the connection.meta
{Object}: Metadata object in the form of key/value pairs.export const CONNECTION_STATUS = {
NOT_CONNECTED: 0,
CONNECTING: 1,
CONNECTED: 2,
ATTEMPTING_RECONNECT: 3,
CONNECT_FAILED: 4
}
Yes, please do! Raise an issue or post a pull request. Let's make working with Holochain a breeze!
AGPL-3.0
FAQs
Provides React apps with easy access to Holochain using the useHolochain() hook
The npm package react-holochain-hook receives a total of 3 weekly downloads. As such, react-holochain-hook popularity was classified as not popular.
We found that react-holochain-hook demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.