---
title: "Components for rendering Sitecore fields"
slug: "components-for-rendering-sitecore-fields"
abstract: "Describes Content SDK components for React that help you render Sitecore fields in Next.js applications."
---
# Components for rendering Sitecore fields

Content SDK provides components that help you render Sitecore fields in your Next.js applications.

The following table shows the correspondence between Sitecore field types and Content SDK components:

| Sitecore field type | Content SDK component |
| --- | --- |
| Date | `DateField` |
| File | `File` |
| Image | `Image`. You can also use the [`NextImage` component](https://doc.sitecore.com/sai/en/developers/content-sdk/20/the-content-sdk-nextimage-component.html "The Content SDK NextImage component"). |
| General Link | `Link` |
| Single-Line Text, Multi-Line Text, or numeric types | `Text` |
| Rich Text | `RichText` |

Import all of these components from `@sitecore-content-sdk/nextjs`. `Link` and `RichText` have Next.js-specific implementations there that add internal link detection, prefetching, and client-side routing on top of the base components in `@sitecore-content-sdk/react`. `DateField`, `Text`, `File`, and `Image` are the same components re-exported from `@sitecore-content-sdk/react`.

The following sections describe the supported components with usage examples. In the examples, `props.fields` is the component's field data, which the `Placeholder` component supplies from the layout data.

## Date

The `DateField` component helps render date and time content fields.

The `DateField` component has the following properties:

| Name | Description |
| --- | --- |
| `field` | Required.<br><br>The field you want to render. It must be a Sitecore Date type. The field data includes the following properties:<br><br><ul><li>`value` - represents the raw field value from the Sitecore item.</li><li>`metadata` - the field metadata that is exposed to allow editing in Pages.</li></ul> |
| `tag` | The name of the HTML element wrapping the date value. If omitted, the value is rendered without a wrapping element.<br><br>Default: none |
| `editable` | Explicitly enable/disable inline editing.<br><br>Default: `true` |
| `render` | A function that receives the field value as a parsed JavaScript `Date` object and returns the value to render in the wrapping `tag` of the component. It can be used to format the value for date and datetime localization. |
| `emptyFieldEditingComponent` | If the field has metadata and an empty value, the component specified here is rendered instead. If this is also empty, the default empty field component is rendered. |

### Usage

To render a date field, import it into your component:

```ts
import { DateField } from '@sitecore-content-sdk/nextjs';
```

You can use the component as follows:

- To render a simple date field:

    ```jsx
    <DateField field={props.fields.date} />
    ```

- To render a datetime field:

    ```jsx
    <DateField field={props.fields.dateTime} />
    ```

- To render a date as a UTC-formatted string:

    ```jsx
    <DateField field={props.fields.date} render={(date) => date?.toUTCString()} />
    ```

    The component provides direct access to the JS `Date` object for formatting purposes. Therefore, you can use it to render localized date and datetime strings as follows:

    ```jsx
    <DateField field={props.fields.date} render={(date) => date?.toLocaleDateString()} />
    <DateField
      field={props.fields.dateTime}
      render={(date) => <em>{date?.toLocaleString()}</em>}
    />
    ```

## File

The `File` component renders a file link.

The `File` component has the following properties:

| Name | Description |
| --- | --- |
| `field` | Required.<br><br>The field you want to render. It represents a Sitecore File type with the properties `src`, `title`, and `displayName`, either directly on `field` or on `field.value`. |
| `children` | A React node, populating the rendered `<a />` tag. The default value is the file's `title` or `displayName`. |

> [!important]
> The `File` component doesn't support inline editing in Pages.

### Usage

To render the file field, import it into your component:

```ts
import { File } from '@sitecore-content-sdk/nextjs';
```

You can use the component as follows:

- To render a simple file link:

    ```jsx
    <File field={props.fields.file} />
    ```

- To render a file link that opens in a new tab with custom anchor text:

    ```jsx
    <File field={props.fields.file} target="_blank">
      View file
    </File>
    ```

## Image

The `Image` component lets you render editable, responsive images. For details on the properties `imageParams`, `srcSet`, and `mediaUrlPrefix` and for examples of specifying media URL query parameters and rendering responsive images, see [The Content SDK Image component](https://doc.sitecore.com/sai/en/developers/content-sdk/20/the-content-sdk-image-component.html).

### Usage

To use the `Image` component, import it into your component:

```ts
import { Image } from '@sitecore-content-sdk/nextjs';
```

You can use the `Image` component to render a simple image:

```jsx
<Image field={props.fields.sample1} />
```

> [!note]
> You can also use the [`NextImage` component](https://doc.sitecore.com/sai/en/developers/content-sdk/20/the-content-sdk-nextimage-component.html), which integrates with `next/image`.

## Link

The `Link` component helps you render the content of the *General Link* Sitecore field.

The component checks whether the link in the Sitecore field is internal, and if so, renders it using the Next.js `Link` component (`next/link`), including prefetching. Otherwise, it renders a plain `<a>` tag.

The `Link` component has the following properties:

| Name | Description |
| --- | --- |
| `field` | Required.<br><br>The field you want to render. It must be a Sitecore *General Link* field type. The field data includes the following properties:<br><br><ul><li>`value` - an object containing link properties such as `href`, `text`, `target`, `title`, `class`, `querystring`, and `anchor`.</li><li>`metadata` - the field metadata that is exposed to allow editing in Pages.</li></ul> |
| `editable` | Explicitly enable/disable inline editing.<br><br>Default: `true` |
| `internalLinkMatcher` | A regex pattern for identifying internal links. Links matching the pattern are rendered with `next/link`; links to files (matched by file extension) are never treated as routes, regardless of this pattern.<br><br>Default: `/^\//g` |
| `showLinkTextWithChildrenPresent` | A boolean that enables or disables the display of the link text even when children exist.<br><br>Default: `false` |
| `renderChildrenWhenEmpty` | When `true`, renders an anchor element containing `children` even when the link field value is empty, instead of rendering nothing.<br><br>Default: `false` |
| `prefetch`, `replace`, `scroll`, `shallow`, `passHref`, `as`, `onNavigate` | Passed through to `next/link` for internal links. `shallow`, `passHref`, and `as` apply only to the Pages Router. See the Next.js `Link` documentation for the [App Router](https://nextjs.org/docs/app/api-reference/components/link) and [Pages Router](https://nextjs.org/docs/pages/api-reference/components/link) for details. |
| `emptyFieldEditingComponent` | If the field has metadata and an empty value, the component specified here is rendered instead. If this is also empty, the default empty field component is rendered. |

### Usage

To use the `Link` component, import it into your component:

```ts
import { Link } from '@sitecore-content-sdk/nextjs';
```

You can use the `Link` component to render:

- External links:

    ```jsx
    <Link field={props.fields.externalLink} />
    ```

- Internal links with HTML or other components:

    ```jsx
    <Link field={props.fields.internalLink}>
      <em>HTML</em> or other components can be used within link renderers, for example, links to images.
    </Link>
    ```

- Email links:

    ```jsx
    <Link field={props.fields.emailLink} />
    ```

The `Link` component accepts additional properties or attributes. The following example displays the link text alongside the child element because `showLinkTextWithChildrenPresent` is `true`:

```jsx
<Link
  field={props.fields.externalLink}
  showLinkTextWithChildrenPresent={true}
  className="font-weight-bold"
  data-otherattributes="pass-through-to-anchor-tag"
>
  <p>Link example</p>
</Link>
```

## Text

The `Text` component helps you render Sitecore fields of type *Single-Line Text*, *Multi-Line Text*, or numeric fields.

The `Text` component has the following properties:

| Name | Description |
| --- | --- |
| `field` | Required.<br><br>The field you want to render. The field data includes the following properties:<br><br><ul><li>`value` - represents the raw field value from the Sitecore item.</li><li>`metadata` - the field metadata that is exposed to allow editing in Pages.</li></ul> |
| `tag` | The name of the HTML element wrapping the text value. If omitted, the value is rendered without a wrapping element, except in editing mode or when `encode` is `false`, where `span` is used. |
| `editable` | Explicitly enable/disable inline editing.<br><br>Default: `true` |
| `encode` | Enables or disables HTML encoding of the output value. Setting this to `false` also makes `editable: false`.<br><br>Default: `true` |
| `emptyFieldEditingComponent` | If the field has metadata and an empty value, the component specified here is rendered instead. If this is also empty, the default empty field component is rendered. |

For a *Multi-line Text* field type, line breaks in the value are replaced with `<br />` elements.

### Usage

To use the `Text` component, import it into your component:

```ts
import { Text } from '@sitecore-content-sdk/nextjs';
```

You can render:

- A text field with default options:

    ```jsx
    <Text field={props.fields.sample} />
    ```

- A non-editable text field with a custom tag, CSS classes, and custom attributes:

    ```jsx
    <Text
      field={props.fields.sample2}
      tag="section"
      editable={false}
      encode={false}
      className="font-weight-bold"
      data-sample="other-attributes-pass-through"
    />
    ```

    > [!important]
    > Setting `encode={false}` outputs raw HTML. Use this option only with trusted content.

If you want to render the raw value of a Sitecore text field, import the `getFieldValue` function. You can then inspect the raw value in your application. For example:

```ts
import { getFieldValue } from '@sitecore-content-sdk/nextjs';
```

```jsx
<div>Raw value (not editable): {getFieldValue(props.fields, 'sample')}</div>
```

## RichText

The `RichText` component helps you render Sitecore *Rich Text* fields.

The component also handles internal links within the rendered HTML: it intercepts clicks on links matching `internalLinksSelector` and routes them client-side, and it prefetches them according to `prefetchLinks`.

The `RichText` component has the following properties:

| Name | Description |
| --- | --- |
| `field` | Required.<br><br>The field you want to render. The field data includes the following properties:<br><br><ul><li>`value` - represents the raw field value from the Sitecore item.</li><li>`metadata` - the field metadata that is exposed to allow editing in Pages.</li></ul> |
| `tag` | The name of the HTML element you want to wrap the text value.<br><br>Default: `div` |
| `editable` | Explicitly enable/disable inline editing.<br><br>Default: `true` |
| `internalLinksSelector` | The CSS selector used to find internal links within the rendered HTML for prefetching and client-side routing.<br><br>Default: `a[href^="/"]` |
| `prefetchLinks` | Controls the prefetch of internal links found via `internalLinksSelector`. This can be beneficial if you have `RichText` fields with large numbers of internal links in them. Can be one of the following:<br><br><ul><li>`true` - all matching links are prefetched as soon as the field renders. This provides the best overall performance but can incur higher resource costs.</li><li>`'hover'` - links are individually prefetched when a user hovers their mouse over them. This offers some performance benefits without a substantial resource cost.</li><li>`false` - links are never prefetched.</li></ul><br><br>Default: `true` |
| `emptyFieldEditingComponent` | If the field has metadata and an empty value, the component specified here is rendered instead. If this is also empty, the default empty field component is rendered. |

### Usage

To use the `RichText` component, import it into your component:

```ts
import { RichText } from '@sitecore-content-sdk/nextjs';
```

You can render:

- A field with default options:

    ```jsx
    <RichText field={props.fields.sample} />
    ```

- A non-editable rich text field with a custom tag, CSS classes, and custom attributes:

    ```jsx
    <RichText
      field={props.fields.sample2}
      tag="section"
      editable={false}
      className="font-weight-bold"
      data-sample="other-attributes-pass-through"
    />
    ```

- A rich text field that prefetches its internal links only on hover, useful when a field contains many links:

    ```jsx
    <RichText field={props.fields.sample} prefetchLinks="hover" />
    ```
