Creating a Sitecore component allows you to easily create a drag-and-drop component. In this article, we will introduce a wizard to help you create this component. The previously introduced steps are as follows
![](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F4xTo93ITUl2V5YT8LtiuHP%2F1046b58d3714f39f4b5cf19bf7bb4f48%2Fxavi-cabrera-kn-UmDZQDjM-unsplash.jpg&w=3840&q=75)
Preparing to use the wizard
We will create components using rendering, but we can manage them separately from existing components by preparing a folder in advance that will serve as a receptacle for them. In this case, we will create a folder called Demo as follows.
- /sitecore/layout/Renderings/Feature/Demo
- /sitecore/system/Settings/Feature/Demo
- /sitecore/templates/Branches/Feature/Demo
- /sitecore/templates/Feature/Demo
For each of the above functions, a folder with the same name, Demo, is prepared, where the wizard will place the necessary data.
Using the Wizard
In this article, we will follow the steps below to create a Headless SXA component. First, right-click on the folder /sitecore/layout/Renderings/Feature/Demo and select Insert - Component.
![xmccomponent01.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F5HgyvcNxJNTiEMnbiFojws%2Fa95fedcbc13131f42bf8548f8b099cad%2Fxmccomponent01.png&w=3840&q=75)
A dialog box will appear immediately. In this case, we will name the component Test.
![xmccomponent02.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F4YQ6wQntIqsqztHRX9khIv%2F7a63d3dd5e3d44fa1544955901b57910%2Fxmccomponent02.png&w=3840&q=75)
Then switch to the Data Sources screen. On this screen, change the Rendering template to Templates/Foundation/JavaScript Services/Json Rendering.
![xmccomponent03.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F2gBnzth2r8YK4T45tKOkx6%2F75d69db7496b80c6bdc86eb5ae0b90fd%2Fxmccomponent03.png&w=3840&q=75)
When completed, the rendering item is created as shown below.
![xmccomponent04.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F3F4ESJXV2kTnuySAYbOOZd%2Fea8010ff5c4fa5cded3aafb87fb08cfb%2Fxmccomponent04.png&w=3840&q=75)
In the rendering definition created, add an entry for IsAutoDatasourceRendering to the Other Properties in the Experience Accelerator group and set it to true.
![xmccomponent05.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F5fCawY5FOLNoztAQVVfo8I%2F463fbb1db4382e914ebcb5da21edf257%2Fxmccomponent05.png&w=2048&q=75)
Now you are ready for the items you need.
Component Creation
For the simplest component, create the following file in the Components folder of Next.js. The file to be created is the same as the name of the component created this time.
import React from 'react';
import { Field, Text } from '@sitecore-jss/sitecore-jss-nextjs';
interface Fields {
TestText: Field<string>;
}
type TestProps = {
params: { [key: string]: string };
fields: Fields;
};
export const Default = (props: TestProps): JSX.Element => {
return (
<div className={`component myrendering ${props.params.styles}`}>
<div className="component-content">
<div>
<strong>テスト:</strong>
<Text field={props.fields.TestText} />
</div>
</div>
</div>
);
};
This code is in the form of getting the data named TestText from the template. This field was not created when the wizard created it, so add the field to /sitecore/templates/Feature/Demo/Data Source/Test that the wizard created.
![xmccomponent06.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F11W7VDKfLeMvWcxYHI6XSB%2F4958de7c450f8c5656ccfb8f9e4b5fe3%2Fxmccomponent06.png&w=3840&q=75)
The component is now ready.
Make it available on your site
After creating a component, it is necessary to define on which site it will be available. In this case, we will create a group called Demo in the sample site, Presentation - Available Rendergins, and add the component we have created so that it can be used.
![xmccomponent07.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F7inFLSLLlyz82wumwBzXJY%2F55e89edf36a2c03bc510eda5a1391784%2Fxmccomponent07.png&w=3840&q=75)
After adding the component, open the Experience Editor and you will see the component displayed.
![xmccomponent08.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F5liqSZbzkxdbxgLcbLCDwG%2F7ce5427046f95c43c6145e8d734c7183%2Fxmccomponent08.png&w=3840&q=75)
When we actually set up the component by drag and drop, we were able to expand the component with editing enabled as we saw it.
![xmccomponent09.png](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fzi1ovlormku8%2F4l9SSwml7p9nJtGvXywox%2F72ae84d87c3a7ffb828b04c0b9a0b006%2Fxmccomponent09.png&w=3840&q=75)
Summary
We have used a wizard to show you how to enable the component in a minimal number of steps. This allows us to simplify the steps to check the behavior on the screen, and then we can work on the data template expansion, manipulate the code of the component, and so on. This wizard is very useful for quickly setting up the minimum and developing components efficiently.