This is unreleased documentation for Yew Next version.
For up-to-date documentation, see the latest version on

Trait yew::html::BaseComponent

source ·
pub trait BaseComponent: Sized + 'static {
    type Message: 'static;
    type Properties: Properties;

    // Required methods
    fn create(ctx: &Context<Self>) -> Self;
    fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool;
    fn changed(
        &mut self,
        ctx: &Context<Self>,
        _old_props: &Self::Properties
    ) -> bool;
    fn view(&self, ctx: &Context<Self>) -> HtmlResult;
    fn rendered(&mut self, ctx: &Context<Self>, first_render: bool);
    fn destroy(&mut self, ctx: &Context<Self>);
    fn prepare_state(&self) -> Option<String>;
Expand description

The common base of both function components and struct components.

If you are taken here by doc links, you might be looking for Component or #[function_component].

We provide a blanket implementation of this trait for every member that implements Component.


This trait may be subject to heavy changes between versions and is not intended for direct implementation.

You should used the Component trait or the #[function_component] macro to define your components.

Required Associated Types§


type Message: 'static

The Component’s Message.


type Properties: Properties

The Component’s Properties.

Required Methods§


fn create(ctx: &Context<Self>) -> Self

Creates a component.


fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool

Updates component’s internal state.


fn changed( &mut self, ctx: &Context<Self>, _old_props: &Self::Properties ) -> bool

React to changes of component properties.


fn view(&self, ctx: &Context<Self>) -> HtmlResult

Returns a component layout to be rendered.


fn rendered(&mut self, ctx: &Context<Self>, first_render: bool)

Notified after a layout is rendered.


fn destroy(&mut self, ctx: &Context<Self>)

Notified before a component is destroyed.


fn prepare_state(&self) -> Option<String>

Prepares the server-side state.

Object Safety§

This trait is not object safe.



impl BaseComponent for Suspense
where Self: 'static,

Available on crate features csr or ssr only.

impl<T> BaseComponent for PhantomComponent<T>
where T: BaseComponent + 'static, Self: 'static,


impl<T> BaseComponent for T
where T: Sized + Component + 'static,