useBackendStrict()
Home > @gooddata/sdk-ui > useBackendStrict
useBackendStrict() function
Hook to get analytical backend instance provided to BackendProvider.
Signature:
useBackendStrict: (backend?: IAnalyticalBackend, context?: string) => IAnalyticalBackend
Parameters
Parameter | Type | Description |
---|---|---|
backend | IAnalyticalBackend | (Optional) backend to use instead of context value. If undefined, the context value is used. |
context | string | (Optional) provide context to improve error message in raised invariant (e.g. parent hook name). |
Returns:
Remarks
You can set a backend override that will be returned if defined. This makes the usage more ergonomic (see the following example).
Note: If you do not provide an IAnalyticalBackend instance to BackendProvider or as a parameter for this hook, an invariant error is raised.
Example
// instead of
const fromContext = useBackendStrict();
const effectiveBackend = fromArguments ?? fromContext.
// you can write
const backend = useBackendStrict(fromArguments);