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.tsx2import { useCall } from "heliumts/client";3import { createTask, getTasks } from "../rpc.generated";45function CreateTaskForm() {6 const save = useCall(createTask, { invalidate: [getTasks] });78 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 };1516 return (17 <form18 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
| Property | Type | Description |
|---|---|---|
submit | Promise<SubmitResult<TResult>> | Handled success, error or busy outcome for ordinary forms |
call | (args: TArgs) => Promise<TResult | undefined> | Function to execute the server method |
isCalling | boolean | Whether one or more calls from this hook are still in progress |
error | string | null | Error message if the call failed |
stats | RpcStats | null | Rate-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});
| Option | Type | Description |
|---|---|---|
invalidate | MethodReference[] | 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) => void | Callback fired after a successful call |
onError | (error: string) => void | Callback fired when the call fails |