/
v3.0.11Get access

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.

NameTypeRequiredDescription
paramsParamsOfFunction<TFn>NoArguments forwarded to the method. Defaults to an empty object. Typed from the method you pass in.
dependenciesDependencyListNoValues that re-trigger the call when they change, like a useEffect dependency array. Defaults to an empty array, so the call runs once.
shouldWaitbooleanNoWhen 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

NameTypeRequiredDescription
dataResponseOfFn<TFn>NoThe response payload. An empty object until the first call resolves.
isLoadingbooleanNoTrue while a call is in flight.
hasErrorbooleanNoTrue when the last call failed.
messagestringNoError text for the last failure, empty otherwise.
statusLOADING | LOADED | FAILEDNoThe 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?