Introduction
Since you're already familiar with Store Framework, you know that we use blocks, like shelf and sku-selector, to create a VTEX IO store. In this step, you're going to create a block that is going to be used in your store's home page theme.
Adding a dummy text to our component
-
In the local template cloned, open up the
Countdown.tsxfile. You will see that it contains a template implementation of a React component, which is an emptydiv, as shown below:_17//react/Countdown.tsx_17import React from 'react'_17_17interface CountdownProps {}_17_17const Countdown: StorefrontFunctionComponent<CountdownProps> = ({}) => {_17return <div></div>_17}_17_17Countdown.schema = {_17title: 'editor.countdown.title',_17description: 'editor.countdown.description',_17type: 'object',_17properties: {},_17}_17_17export default CountdownSome things to pay attention:
-
The typings for the component props are defined in here:
_10interface CountdownProps {} -
This schema refers to the content that it's shown in the Site Editor:
_10Countdown.schema = {_10title: 'editor.countdown.title',_10description: 'editor.countdown.description',_10type: 'object',_10properties: {},_10}
In order for your block to accept user customizations, you need to export a
schemain the React component responsible for the block using JSON schema. This will, automatically, generate a form in Site Editor linked to the block that you're developing. -
-
Now, let's add a
h1tag inside the component._10const Countdown: StorefrontFunctionComponent<CountdownProps> = ({}) => {_10- return <div></div>_10+ return (_10+ <div>_10+ <h1>Countdown Test</h1>_10+ </div>_10+ )_10} -
Now, in order to see the block that you've just created, it's necessary for you to declare the block that the app defines in a theme.
Which theme should I use?
In case of already having a theme from the previous courses, you can use it. However, if you do not have one, you can use
vtex.store-theme, which can be cloned by running this command in your terminal._10git clone https://github.com/vtex-apps/store-theme.gitNote: It can be cloned in a folder of your preference, but not inside the app's directory that you're developing.
Now, to avoid conflicts, go to your terminal and unlink any theme or apps you have linked
_10vtex unlink --allWith both repositories ready to go, one need to link both, in two different terminals, using the following command:
_10vtex linkRemember to use your own workspace!
-
With both links active (theme and custom block), let's add the block into the theme. To do that, it's necessary to add it in the theme's dependencies:
_10{_10..._10"dependencies": {_10..._10+ "vtex.countdown": "0.x",_10..._10},_10..._10} -
And lastly, we do want to add the block to the store, in order for it to be seen. Inside the file
store-theme/store/blocks/home/home.jsonc, declarecountdownblock:_10{_10"store.home": {_10"blocks": [_10+ "countdown",_10..._10]_10..._10}_10..._10}
The expected result is to find a h1 in the top of the store, you can see it below:

In case of adding the block as the last one on the
store.home, you're going to see it in the bottom of the page.