LNG LogoLNG Logo
    • Enterprise App Development
    • Product Architecture Design
    • Data Engineering & Analytics
    • Cloud Consulting Services
    • AI-Enabled Applications
    • Remote Engineering Teams
    • UI/UX Design
    • Data Migration
    • Big Data
    • DevOps Solutions
    • Banking
    • Ecommerce
    • Fintech
    • Healthcare
    • Hospitality
    • Manufacturing
    • Telecom
    • Travel
    • Education
    • Cross-Platform & Web Development
    • Digital Experience Platform
    • Enterprise Technologies
    • Modern Frontend Interface
    • About Us
    • Blog
    • Our Team
    • Careers
    • Success Stories
Let's Talk !

Build SXA Custom Components in XM Cloud | L&G

By: Koushik MukherjeeNovember 20, 2024

 

XM Cloud comes preloaded with basic components for text, images, page content, and more. In my previous blogs, I covered how to create and manage components in XM Cloud using the Component Builder. In this post, I’ll provide a step-by-step guide to building custom components in Next.js within the XM Cloud environment.

Why Custom Components Matter

Developing custom components is a standard approach to creating unique elements that enhance your pages’ design, functionality, and user experience.

Step 1: Creating a New Headless Module

To create a custom component in Sitecore XM Cloud, you first need to set up a Headless Module. Here’s how:

  1. Navigate to Settings -> Project -> [Site Name] in XM Cloud.
  2. Right-click your project, select Insert, and then click Headless Module.Insert headless module option
  3. In the popup window, choose a name for the module (e.g., Custom Component) and assign it to a folder. For this tutorial, we created a “Tutorial Site” folder under Feature to store our custom modules like Basic Content.
Headless module creation window

Step 2: Cloning a Rendering

After creating the module, clone an existing out-of-the-box (OOTB) Headless rendering to save time. For this example, we’ll clone the Promo component.

  1. Right-click the rendering, navigate to Scripts, and select Clone Rendering.
    Context menu in content editor
  2. In the popup, provide a name for the new rendering (e.g., Article) and link it to the module created earlier.
    Derivative rendering creation window
  3. Ensure the Parameters and Data Source tabs have Copy Original Rendering Parameters selected.Rendering parameters window
    Datasource selection window

Next, locate the template under Templates/Feature/Tutorial Site/Custom Component. Update the Article template to include fields specific to your new component.

Template builder interface

 

Step 3: Importing the Component Module to the Site

Once the template is ready, the module can be added to your site:

  1. Use the Scripts -> Add Site Module command.
    Sitecore site module options
  2. In the popup, select your new module for installation.
    Module selection window
  3. A corresponding Data folder will be created for storing content items.
    Insert article option
    Content editing window

Add the component to Presentation -> Available Renderings to make it accessible for drag-and-drop functionality on pages.

Custom Component details view

Finally, open the page editor, locate your component, and place it on the desired page. Ensure all related items are published in XM Cloud to avoid visibility issues.

Component selection panel

Step 4: Creating SXA Components in Code

TypeScript View File

The TypeScript file for your component must match the Component Name field on the rendering item in XM Cloud. Use the withDatasourceCheck higher-order component to fetch and render data from the Sitecore Content API. Key libraries include @sitecore-jss/sitecore-jss-nextjs for managing field types like Field, ImageField, Text, and Link.

  1. Create the view file in the src/components/rendering folder.
  2. Scaffold the component using the JSS command:
    jss scaffold “Article”
  3. Alternatively, create the component manually. Ensure the fields are editable in Experience Editor and render correctly in preview mode.Code editor with React component
    import React from ‘react’;
    import { ComponentParams, ComponentRendering } from ‘@sitecore-jss/sitecore-jss-nextjs’;
    import {Image as JssImage, Link as JssLink, RichText as JssRichText, ImageField, Field, LinkField, Text
    } from ‘@sitecore-jss/sitecore-jss-nextjs’;
    interface Fields {
        Title: Field<string>;
      Summary:Field<string>;
      Description: Field<string>;
      Photo: ImageField;
      ArticleLink: LinkField;
    };
    interface ArticleProps {
      rendering: ComponentRendering & { params: ComponentParams };
      params: ComponentParams;
      fields: Fields;
    }
    const ArticleComponent = (props: ArticleProps): JSX.Element => (
      <div className={`component article-component ${props.params.styles}`}>
        <div className=”component-content”>
          <span className=”is-empty-hint”>Please assign a datasource item to edit the content.</span>
        </div>
      </div>
    );
    export const Default = (props: ArticleProps): React.JSX.Element => {
      const id = props.params.RenderingIdentifier;
      if (props.fields) {
        return (
          <div className={`component my-component ${props.params.styles}`} id={id ? id : undefined}>
            <JssImage field={props.fields.Photo} />
            <div>
              <h2>
                <Text field={props.fields.Title} />
              </h2>
              <JssRichText field={props.fields.Description} />
              <JssLink field={props.fields.ArticleLink} />
            </div>
          </div>
        );
      }
      return <ArticleComponent {…props} />;
    };

Step 5: Testing and Launching the Component

Fetch data via the Layout Service or GraphQL API, using the ComponentRendering object from the JSS SDK to map XM Cloud fields to the component structure.

Run the following command to test your component in connected mode:

npm run start:connected

This launches the app locally at http://localhost:3000, allowing you to preview and refine your component.

Article page with an image of hands united

Conclusion

Building custom components in Sitecore XM Cloud with Next.js is a streamlined process. By following these steps—creating modules, cloning renderings, scaffolding, and testing—you can develop engaging, dynamic components tailored to your project. Dive in and elevate your XM Cloud applications with polished, user-focused designs!


Custom ComponentSitecoreSXA ComponentXM CloudXMCloud Components
Two CMSs, One Website: Managing Routing During WordPress to Sitecore MigrationJune 17, 2026Mastering Identity Resolution in Sitecore CDP: Anonymous to Known VisitorsMay 25, 2026

Let's Innovate, Collaborate, Build Your Product Together!

We turn your unique ideas into exceptional results. Contact us to
scale your tech capacity and accelerate business growth.

Let's Talk!
Where We Are

Our Global Presence

Delivering world-class digital solutions from three strategic locations across the globe.

South AfricaSouth Africa
ZACape Town

4th Floor, Mutual Park, Pinelands, Capetown, South Africa - 7405.

UAEUAE
AEDubai

FZCO 421, Dubai Commercity, Dubai, United Arab Emirates.

IndiaIndia
INAmritsar

SCO 6, Floor - 5, Dua Square, Ranjit Avenue, Block - B, Amritsar, Punjab, India - 143002

Logo

AI-Fuelled software agency, helping business professionals to thrive. Trusted by global leaders.

Company

  • About Us
  • Blog
  • Our Term
  • Careers
  • Success Stories

Services

  • AI-Enabled Applications
  • Big Data
  • Cloud Consulting Services
  • Data Engineering & Analytics
  • Data Migration
  • DevOps Solutions
  • Enterprise Application Development
  • Product Architecture Design
  • Remote Engineering Teams
  • UI/UX Design

Industries

  • Banking
  • Ecommerce
  • Fintech
  • Healthcare
  • Hospitality
  • Manufacturing
  • Telecom
  • Travel & Transport
  • Education

Technologies

  • Cross-Platform and Web Development
  • Digital Experience Platform
  • Enterprise Technologies
  • Modern Frontend Interface
Logo

AI-Fuelled software agency, helping business professionals to thrive. Trusted by global leaders.

Company
  • About Us
  • Blog
  • Our Term
  • Careers
  • Success Stories
Services
  • AI-Enabled Applications
  • Big Data
  • Cloud Consulting Services
  • Data Engineering & Analytics
  • Data Migration
  • DevOps Solutions
  • Enterprise Application Development
  • Product Architecture Design
  • Remote Engineering Teams
  • UI/UX Design
Industries
  • Banking
  • Ecommerce
  • Fintech
  • Healthcare
  • Hospitality
  • Manufacturing
  • Telecom
  • Travel & Transport
  • Education
Technologies
  • Cross-Platform and Web Development
  • Digital Experience Platform
  • Enterprise Technologies
  • Modern Frontend Interface

Copyright © 2026 L&G Consultancy. All Rights Reserved.
Privacy PolicyTerms and Conditions
Company Image