@usearete/react
v0.2.0
Published
React SDK for the Arete Solana developer platform
Maintainers
Readme
Arete React SDK
React hooks and provider for consuming Arete stacks in React applications.
Built on top of @usearete/sdk, the framework-agnostic TypeScript core SDK.
Installation
npm install @usearete/react react zustandNot using React? Use
@usearete/sdkdirectly.
Quick Start
import { AreteProvider, useArete } from '@usearete/react';
import { ORE_STREAM_STACK } from './generated/ore-stack';
function Dashboard() {
const { views, isLoading, error } = useArete(ORE_STREAM_STACK, {
url: 'ws://localhost:8877',
httpUrl: 'http://localhost:8877',
});
const { data: latestRound } = views.OreRound.latest.useOne();
if (isLoading) {
return <div>Connecting...</div>;
}
if (error) {
return <div>{error.message}</div>;
}
return <pre>{JSON.stringify(latestRound, null, 2)}</pre>;
}
export default function App() {
return (
<AreteProvider
autoConnect={true}
auth={{
// publishableKey: 'hspk_...',
}}
>
<Dashboard />
</AreteProvider>
);
}Provider
AreteProvider manages connected clients for descendant hooks.
Supported props:
autoConnectwalletauthfetchvalidateFramesreconnectIntervalsmaxReconnectAttemptsmaxEntriesPerViewflushIntervalMs
These are provider-wide defaults. Endpoint overrides stay on the hook call.
useArete(stack, options?)
useArete returns the connected React surface for a stack:
viewsprogramsquerieschainclientconnectionStateisConnectedisLoadingerror
Supported hook options:
urlhttpUrltransportprograms
Notes:
transport: 'http'disables streaming view subscriptions, but HTTP-backed surfaces likequeries,chain, and program reads still work.- If you pass attached
programs, keep that object stable with a module constant oruseMemoso React does not create a fresh client on every render.
Views
View hooks return a ViewHookResult<T> object:
type ViewHookResult<T> = {
data: T | undefined;
isLoading: boolean;
error?: Error;
refresh: () => void;
};List views support:
.use().use({ take: 1 }).useOne()
State views support:
.use(key)
Programs, Queries, and Chain
useArete mirrors the connected core client surface:
programs.<program>.raw.<instruction>for raw typed instructionsprograms.<program>.plan/programs.<program>.instructionsfor semantic instructionsprograms.<program>.accountsandprograms.<program>.queriesfor HTTP readsqueriesfor stack-level HTTP querieschainfor chain helpers
Raw instruction hooks preserve .execute, .build, and .useMutation().
Semantic instruction hooks preserve:
.execute.send.resolve.plan.build.stage.useMutation()
Low-Level Hooks
The React SDK also exports:
useConnectionStateuseViewuseEntityuseAreteContext
These accept the same client lookup overrides when you need to target a non-default client.
Relationship with @usearete/sdk
@usearete/react re-exports selected core APIs and types for convenience, but it is not a complete mirror of the core package.
If you need the full low-level surface, import directly from @usearete/sdk.
License
MIT
