props
.
In this tutorial you’ll learn how to fetch data from an external API and feed
that into a Section using Loaders.
What we’ll build
The example use-case we’ll follow is simple, but it has a lot of complexities we have on data fetching:- Fetch dog facts data from the Dog API allowing the user to configure how many facts are being fetched on deco.cx’s Admin.
- Render those facts in a Section.


1. Creating the Section
First, let’s create a Section that will render the data fetched from the API. Create the DogFacts.tsx section in the sections/ folder of your project. If we make an HTTP request to the Dog Fact API, we will see that it returns a JSON in the following format:Open in your browser this URL with params for the Dog Fact API
At this point, you can check in the admin (in your local environment) that this component can already be used with static data, which doesn’t make much sense for our use case.
2. Creating the Loader and testing the Section
Now let’s create a Loader that will fetch the data from the Dog Fact API and pass it to the Section. Loaders allow you to define how data is fetched and transformed before it is passed on to a Section. They are regular Typescript functions that can use async functions likefetch
. Loaders can be “plugged” into a Section via one
of the Section’s props
, and that happens based on the return type of the
Loader (the return type of the Loader is the input type of the Section).
- Define what will be the input
Props
of your loader. - Export a function called
loader
in the same file as your Section.
Note: The SectionProps
type is a helper type that is used to infer the
return type of the loader.
3. Testing the Section
- Run the server locally with
DECO_ENV_NAME={environment_name} deno task start
. - Go to
https://deco.cx/admin
in your site and make sure that your environment is selected in the Environment Selector in the upper right corner of the Admin. - Go to
Sections
and search for DogFacts in the left sidebar. - Configure the props of the selected Loader (numberOfFacts) with a desired number (e.g., 4).

props
to
make it more reusable in deco.cx’s Admin.