Components#
In HTML, there are tags like div, span, input, button, which describe the structure of the UI.
Elements are represented by classes like Div, Span,
Input, Button, which are subclasses of the
Element class.
Components are subclasses of the base Component class and are used to create reusable
and more complex UI structures.
For example, an AppButton component can be created which can be used throughout the application.
To create a component, create a class which inherits from Component class and define the
render method which returns the Element or Component which will be rendered.
The render method can return a single Element, Component
or one of the primitive types:
str
int
float
bool
None
Except for the actual return value which can be only single Element, Component or one of the primitive types, components and elements can have any number of children.
To return multiple components from the render method, use the Fragment component.