React Reference

useYagna

useYagna is a hook that provides information about the Yagna connection status. If the connection cannot be established, the hook will retry using an exponential backoff algorithm. It returns an object with the following properties:

NameDescription
isConnectedBoolean indicating whether the connection to Yagna is established.
isLoadingBoolean indicating whether the connection to Yagna is being established.
errorError object containing information about the error that occurred while connecting to Yagna.
reconnectA function that can be used to reconnect to Yagna.
setYagnaOptionsA function that can be used to set the app-key and base path for Yagna.
isAppKeySetBoolean indicating whether the app-key for Yagna is set.
appKeyThe current app-key for Yagna.
basePathThe current url for Yagna.

Parameters

This hook doesn't accept any parameters.

Example

function MyComponent() {
  const { isConnected, appKey, setYagnaOptions } = useYagna()
  const inputRef = useRef(null)
  return (
    <div>
      <div>Connected to Yagna: {isConnected ? 'yes' : 'no'}</div>
      <input ref={inputRef} />
      <button
        onClick={() => setYagnaOptions({ apiKey: inputRef.current.value })}
      >
        Set app key
      </button>
    </div>
  )
}

Was this helpful?