pub trait Component: Sized + 'static {
type Props: Props;
type State: State;
// Required methods
fn initial_state(props: &Self::Props) -> Self::State;
fn render(props: &Self::Props, state: &Self::State) -> RenderOutput;
fn on_event(
props: &Self::Props,
state: &mut Self::State,
event: ComponentEvent,
) -> EventResult;
// Provided methods
fn props_changed(
_old_props: &Self::Props,
_new_props: &Self::Props,
_state: &mut Self::State,
) -> bool { ... }
fn cleanup(_props: &Self::Props, _state: &mut Self::State) { ... }
}Expand description
The core trait all NexusStratum UI components implement.
Component defines the framework-agnostic lifecycle of a UI component:
- Initialize state from props
- Render a framework-agnostic description of the component
- Handle events and update state
Framework adapters (stratum-leptos, stratum-dioxus) bridge this trait to each framework’s specific rendering and reactivity model.
Required Associated Types§
Required Methods§
Sourcefn initial_state(props: &Self::Props) -> Self::State
fn initial_state(props: &Self::Props) -> Self::State
Create the initial state from the given props.
Sourcefn render(props: &Self::Props, state: &Self::State) -> RenderOutput
fn render(props: &Self::Props, state: &Self::State) -> RenderOutput
Produce a framework-agnostic render description.
The returned RenderOutput describes the component’s attributes,
CSS classes, ARIA attributes, and children. Framework adapters
translate this into actual DOM/VDOM elements.
Sourcefn on_event(
props: &Self::Props,
state: &mut Self::State,
event: ComponentEvent,
) -> EventResult
fn on_event( props: &Self::Props, state: &mut Self::State, event: ComponentEvent, ) -> EventResult
Handle an event and optionally mutate state.
Returns an EventResult indicating whether the event should
be prevented, stopped, or if state changed (triggering re-render).
Provided Methods§
Sourcefn props_changed(
_old_props: &Self::Props,
_new_props: &Self::Props,
_state: &mut Self::State,
) -> bool
fn props_changed( _old_props: &Self::Props, _new_props: &Self::Props, _state: &mut Self::State, ) -> bool
Called when props change. Returns true if state needs updating.
Default implementation always returns false (state is independent of props). Override for components where prop changes should sync to state.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.