React hooks
Build your own feedback interface with hooks from reflet-sdk/react. React and React DOM 18 or 19 are required.
Mount the provider
"use client";
import type { ReactNode } from "react";
import { RefletProvider } from "reflet-sdk/react";
export function FeedbackProvider({
children,
userToken,
}: {
children: ReactNode;
userToken?: string;
}) {
return (
<RefletProvider
publicKey="fb_pub_YOUR_PUBLIC_KEY"
userToken={userToken}
>
{children}
</RefletProvider>
);
}In Next.js, put hooks and this wrapper in a client component. Fetch signed tokens through your app's authenticated server flow, then pass them as userToken. The provider accepts publicKey, baseUrl, user, and userToken, with the same access boundaries as the client.
useRefletClient()returns the current client for methods without a hook.useRefletContext()returns the client, publicKey, baseUrl, user, userToken, setUser, and isReady. Both hooks throw outside a provider.isReadymeans client hydration has occurred. It does not verify the API key, network, or sign-in.userinitializes local state only. Use the context'ssetUserfor later unsigned identity changes. A supplied userToken takes priority; update or remove that prop when refreshing a token or signing out.
Read data
"use client";
import { useFeedbackList } from "reflet-sdk/react";
export function RecentFeedback() {
const { data, error, isLoading, refetch } = useFeedbackList({
sortBy: "newest",
limit: 20,
});
if (error) {
return (
<div role="alert">
<p>{error.message}</p>
<button onClick={() => void refetch()} type="button">Try again</button>
</div>
);
}
if (isLoading && !data) return <p>Loading feedback...</p>;
if (!data?.items.length) return <p>No feedback yet.</p>;
return <ul>{data.items.map((item) => <li key={item.id}>{item.title}</li>)}</ul>;
}Queries return data (initially undefined), isLoading, error (initially null), and refetch(). They run on mount and when their client or arguments change. A failed refetch keeps previous data and stores the error rather than rejecting the refetch promise. Disabled queries do not run automatically; calling refetch still runs the request.
Each hook owns its own state. There is no shared query cache, background polling, automatic pagination, or cross-component invalidation. See the client guide for filters.
Write and refresh
Mount this example under a provider with a signed userToken. After a successful mutation, refetch the affected query yourself. Mutations do not optimistically change query results.
"use client";
import { useFeedbackList, useVote } from "reflet-sdk/react";
export function FeedbackVotes() {
const list = useFeedbackList({ sortBy: "votes" });
const vote = useVote();
async function handleVote(feedbackId: string) {
try {
await vote.mutate({ feedbackId });
await list.refetch();
} catch {
// The mutation stores this error for the alert below.
return;
}
}
return (
<section>
{list.isLoading && <p>Loading feedback...</p>}
{(list.error || vote.error) && (
<p role="alert">{(list.error ?? vote.error)?.message}</p>
)}
<ul>
{list.data?.items.map((item) => (
<li key={item.id}>
{item.title}
<button
disabled={vote.isLoading}
onClick={() => void handleVote(item.id)}
type="button"
>
{item.hasVoted ? "Remove vote" : "Vote"} ({item.voteCount})
</button>
</li>
))}
</ul>
</section>
);
}The create, vote, and comment hooks return mutate, data, isLoading, error, and reset. mutate both stores failures and rejects, so catch it in event handlers. reset() clears stored data and error; it does not cancel a request. For status-specific UI, inspect RefletError.
Use ready-made components
The same React entry exports FeedbackButton and FeedbackDialog, ChangelogWidget, and survey delivery and rendering. Import RefletFeedback from reflet-sdk/feedback for the floating capture widget.