HeliumTS is under active development and may have bugs or breaking changes. Report issues on GitHub.

Data Mutation

HeliumTS provides the useCall hook for performing mutations (create, update, delete operations). Unlike useFetch, it doesn't automatically execute — you call it manually when needed.

useCall

The useCall hook is designed for writing/modifying data. It provides a function to trigger the server method and tracks the execution state.

Basic Usage

1// src/components/CreateTaskForm.tsx
2import { useCall } from "heliumts/client";
3import { createTask, getTasks } from "../rpc.generated";
4
5function CreateTaskForm() {
6 const save = useCall(createTask, { invalidate: [getTasks] });
7
8 const handleSubmit = async (name: string) => {
9 const result = await save.submit({ name });
10 if (result.status === "success") {
11 console.log("Task created:", result.data);
12 }
13 // error: save.error is displayed below; busy: no second request.
14 };
15
16 return (
17 <form
18 onSubmit={(e) => {
19 e.preventDefault();
20 const form = new FormData(e.currentTarget);
21 void handleSubmit(String(form.get("taskName") ?? ""));
22 }}
23 >
24 <label htmlFor="task-name">Task name</label>
25 <input id="task-name" name="taskName" required />
26 <button type="submit" disabled={save.isCalling}>
27 {save.isCalling ? "Creating..." : "Create Task"}
28 </button>
29 {save.error && <p role="alert">{save.error}</p>}
30 </form>
31 );
32}

submit returns a typed success, error or busy outcome and suppresses another submission while this hook has a pending call. It does not provide server idempotency or deduplication across components. Invalidation starts the normal eventual refresh; it does not wait for every related read. An error after a callback failure does not prove that a committed write was rolled back.

Use call for concurrent or advanced promise flows. It rejects on failure, so catch its promise in event handlers. submit is available in the 0.11.0 release.

Return Values

PropertyTypeDescription
submitPromise<SubmitResult<TResult>>Handled success, error or busy outcome for ordinary forms
call(args: TArgs) => Promise<TResult | undefined>Function to execute the server method
isCallingbooleanWhether one or more calls from this hook are still in progress
errorstring | nullError message if the call failed
statsRpcStats | nullRate-limit statistics: remaining requests and seconds until the limit resets

Options

1const { call } = useCall(method, {
2 invalidate: [getTasks, getTaskCount],
3 onSuccess: (result) => console.log("Success:", result),
4 onError: (error) => console.error("Error:", error),
5});
OptionTypeDescription
invalidateMethodReference[]Array of methods whose cached data should be invalidated after a successful call. This triggers automatic refetch for all useFetch hooks using those methods.
onSuccess(result: TResult) => voidCallback fired after a successful call
onError(error: string) => voidCallback fired when the call fails