Creates a Component

the sample of a component

HelloComponent

Kagura recomends to create a component by file. Basically, file and component have same name.

src/hello_component.rs
use kagura::pelude::*;
use nusa::prelude::*;

pub struct Props {}

pub enum Msg {}

pub enum On {}

pub struct HelloComponent {}

impl Component for HelloComponent {
    type Props = Props;
    type Msg = Msg;
    type Event = On;
}

impl HtmlComponent for HelloComponent {}

impl Constructor for HelloComponent {
    fn constructor(_props: Self::Props) -> Self {
        Self {}
    }
}

impl Update for HelloComponent {}

impl Render<Html> for HelloComponent {
    type Children = ();
    fn render(&self, _children: Self::Children) -> Html {
        Html::h1(
            Attributes::new(),
            Events::new(),
            vec![Html::text("Hello Component")]
        )
    }
}

Mounts a Component

Last updated