Content call
Calls a Content CMS method and exposes the result as React state. It re-runs whenever its dependencies change.
Show as
Import from@softconstruct/betchain-core-client/hooks
Use it whenMenus, banners, promotions, bonuses and payment-system settings.
Signature
.ts
useContent(functionRef: TFn, options: {
params?: ParamsOfFunction<TFn>;
dependencies?: DependencyList;
shouldWait?: boolean;
}): {
data; status; message; hasError; isLoading;
}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. |
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. |
Example
.ts
1import {2 getPromotions3} from '@softconstruct/betchain-core-client/content';4import {5 useContent6} from '@softconstruct/betchain-core-client/hooks';7 8const {9 data,10 isLoading,11 hasError,12 message13} = useContent(getPromotions, {14 params: {},15 dependencies: []16});Notes
No makeRequestUnlike useCasino and useSwarmGetOnce, this hook returns state only. To refetch, change a value in dependencies.
Was this page helpful?