How to Create a Component in Next.js for XM Cloud
Let’s create a component in the Next.js app.
If you want to know how that component is created in XM Cloud, please refer to my previous blog for more information.
https://sitecoresathiya.blogspot.com/2024/10/how-to-create-component-in-nextjs-for-xmc.html
I have pulled down the startup branch to my local environment.
https://github.com/sitecorelabs/xmcloud-foundation-head
Refer to the README file to learn how to run the Next.js app locally.
Navigate to the headapps/nextjs-starter folder and execute the following command to scaffold a new component:
jss scaffold "TextCard".
Let's check if the component is rendered correctly. Run the command below to start your Next.js app locally in connected mode.
npm run start:connected
After that, your app will run on http://localhost:3000/ with the default port if the port is not in use.
Yes, it shows what I had in my TextCard.tsx file.
How can we display the content from XMC?
To map the component fields into my TextCardFields object and pass that as props.
Here’s a guide on how to use Sitecore fields in Next.js.
After applying the CSS changes, my component looks much better.
Comments
Post a Comment