Working with components

Components are the building blocks of toddle applications. Components lets you reuse generic parts of your application like a Navigation bar or a Popup. Components are also a great way to break large applications down in to smaller more manageable building blocks.

Components can render elements on a page, store data in variables, call APIs etc. You can kind of think of them as tiny web applications on their own.

Components in toddle encapsulates their data. This means that the variables and APIs of one component are not accessible by other components. Initially this can seem unnecessarily restrictive, but it is a critical property that lets you reason about your application as the number of components grow.

Components are composable

Components in toddle can be composed together to form more complex components which then in turn can be composed into full applications.

And application like the toddle editor contains dozens of API calls, and thousands of variables. Trying to keep all that information in your head ad one time would be impossible. Using components we can split the editor into hundreds of smaller components, each responsible for a small part or the application.
element-panel being developed in the toddle editor.

Components can send data to other components and pages through Attributes and Events .

Creating a new component

There are two ways you can create a new component. You can create a new component from the project sidebar by clicking "Create new" followed by "New component".

Create a new component from the project sidebar.

The other option is to right click an element inside the element tree and choose extract as component.

Create new component from the element tree
Components in toddle follow the naming restrictions of web-components . A component must have at least two parts to their name joined together by a hyphen "-", Component names cannot contain any special characters.

You can read more about how to use components in toddle in Component elements

Learn more about components: