loadSlotContent

Learn how to asynchronously retrieve default slot content.

This function asynchronously retrieves the default content for a Slot from the @croct/content package.

Croct's mascot winking
Lazy loading

When using bundlers that support code splitting, prefer this function over its sync counterpart, as it enables lazy loading of content modules.

Signature

This function has the following signature:

loadSlotContent(slotId: string, language?: string): Promise<JsonObject | null>

The return is a Promise that resolves to the content as a JSON object, or null if no content is available for the given slot and locale.

Example

Here is a minimal example of how to use this function:

1234567
import {loadSlotContent} from '@croct/content';
const content = await loadSlotContent('home-hero');
if (content !== null) {  console.log(content.title);}

Parameters

The following list describes the supported parameters:

slotId
string

The slot identifier, for example home-hero.

language(optional)
string

The locale code, for example en. If omitted, defaults to the project's default locale.