Other
There are some auxiliary hooks that you may use:
useNilPoolStatus
Pool Status refers to the preprocessing pool's status. A simple call to the hook should provide their status.
examples-nextjs/app/components/pool-status.tsx
"use client";
import { useNilPoolStatus } from "@nillion/client-react-hooks";
import type { FC } from "react";
export const PoolStatus: FC = () => {
const mutation = useNilPoolStatus();
let data = "";
if (mutation.isSuccess) {
// stringify cannot handle BigInts
data = JSON.stringify(mutation.data, (_, v) =>
typeof v === "bigint" ? v.toString() : v,
);
} else if (mutation.isError) {
data = mutation.error.message;
}
return (
<div>
<h2>Query Pool Status</h2>
<ol>
<li>Status: {mutation.status}</li>
<li>Result: {data}</li>
</ol>
<button type="button" onClick={(): void => mutation.execute()}>
Execute
</button>
</div>
);
};
useNillion
This hook gives all access to the aforementioned properties of all of hooks.
import { useNillion } from "@nillion/client-react-hooks";
...
const nillion = useNillion()
...
nillion.client.XXX // whatever you want to use from the client.
Below is the source code for reference
client-react-hooks/src/use-nillion.ts
import { useContext } from "react";
import { NillionContext } from "./nillion-provider";
export function useNillion(): NillionContext {
const context = useContext(NillionContext);
if (!context) {
throw new Error("NillionContext is undefined");
}
return context;
}