Component API
collagraph.Component
Base class for all components.
Properties
| Property | Type | Description |
|---|---|---|
props |
readonly(dict) |
Read-only incoming props from parent |
state |
reactive(dict) |
Reactive local state |
refs |
reactive(dict) |
Template refs (elements/components) |
element |
varies | The root platform element |
parent |
Component \| None |
Parent component (None for root) |
Lifecycle Hooks
init()
Called after __init__ completes. Use this to initialize state:
mounted()
Called after the component and all its children are mounted in the element tree:
updated()
Called after the component's DOM tree has been updated due to a reactive state change:
before_unmount()
Called right before the component is removed. Clean up side effects here:
Methods
emit(event, *args, **kwargs)
Emit a custom event to the parent component:
provide(key, value)
Make a value available to all descendant components:
inject(key, default=None)
Retrieve a value provided by an ancestor component:
render(renderer) -> ComponentFragment
Abstract method. Normally generated automatically from the .cgx template. Only override this for pure-Python components (no template):