Get once
Calls a Swarm method once and resolves with the result. It re-runs when its dependencies change and also exposes makeRequest so you can trigger the call yourself.
Show as
Import from@softconstruct/betchain-core-client/hooks
Use it whenOne-off retrieval: profile data, static catalogs, initial balances.
Signature
.ts
useSwarmGetOnce(functionRef: TFn, options: {
params?: ParamsOfFunction<TFn>;
dependencies?: DependencyList;
shouldWait?: boolean;
successCallback?: (data?: ResponseOfFn<TFn>) => void;
}): {
data; status; errorMessage; hasError; isLoading; makeRequest;
}Options
Passed as the second argument, except for useInitSDK which takes a single config object.
| Name | Type | Required | Description |
|---|---|---|---|
params | ParamsOfFunction<TFn> | No | Arguments forwarded to the method. Defaults to an empty object. Typed from the method you pass in. |
dependencies | DependencyList | No | Values that re-trigger the call when they change, like a useEffect dependency array. Defaults to an empty array, so the call runs once. |
shouldWait | boolean | No | When true the hook does not fire on mount. Use it to defer a call until a prerequisite (an id, a logged-in session) is ready. Defaults to false. |
successCallback | (data?: ResponseOfFn<TFn>) => void | No | Invoked with the response after a successful call. |
Returns
| Name | Type | Required | Description |
|---|---|---|---|
data | ResponseOfFn<TFn> | No | The response payload. An empty object until the first call resolves. |
isLoading | boolean | No | True while a call is in flight. |
hasError | boolean | No | True when the last call failed. |
message | string | No | Error text for the last failure, empty otherwise. |
status | LOADING | LOADED | FAILED | No | The raw request status, if you need more than isLoading. |
makeRequest | (overrideParams?) => Promise<Result> | No | Runs the call on demand, optionally with different params. Useful together with shouldWait. |
Example
.ts
1import {2 getCompetitions3} from '@softconstruct/betchain-core-client/swarm';4import {5 useSwarmGetOnce6} from '@softconstruct/betchain-core-client/hooks';7 8const {9 data,10 isLoading,11 hasError,12 errorMessage13} = useSwarmGetOnce(getCompetitions, {14 params: {15 limit: 10,16 isFavorite: true,17 onlyLiveGames: true18 },19 dependencies: []20});Notes
Response type follows your paramsThe return type is narrowed from the method and the params you pass, so data is typed without any casting on your side.
Was this page helpful?