Scaffolding components in JSS apps

Version: 22.x

Creating new components is a common task while developing JSS applications.

To make it easy to create components, JSS Next.js sample applications provide a scaffolding script that you can invoke with the JSS CLI. Running the following command in the root of your JSS head app will create a new component file named ComponentName.tsx:

RequestResponse
jss scaffold ComponentName

By default, the command creates the component file in the folder src/components/ within your app. If you want to create a new component in a subfolder of this location instead, you can specify that subfolder as part of the command. The following example creates a file named SecondComponentName.tsx in the folder src/components/seo/:

RequestResponse
jss scaffold seo/SecondComponentName

When you build your application with jss build, the Component Builder located at src/temp/componentBuilder.ts is updated to import and map any new components within the src/components/ folder.

Do you have some feedback for us?

If you have suggestions for improving this article,