yewstack / docs

https://yew.rs
Creative Commons Zero v1.0 Universal
45 stars 46 forks source link

Sample code error . #7

Closed Ticsmtc closed 4 years ago

Ticsmtc commented 4 years ago

In "Use html!", Elements -> Listeners -> Component Handler

struct MyComponent {
    link: ComponentLink<Self>,
}

enum Msg {
    Click,
}

impl Component for MyComponent {
    type Message = Msg;
    type Properties = ();

    fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
        MyComponent { link }
    }

    fn update(&mut self, msg: Self::Message) -> ShouldRender {
        match msg {
            Msg::Click => {
                // Handle Click
            }
        }
    }

    fn view(&self) -> Html<Self> {
        // Create a callback from a component link to handle it in a component
        let click_callback = self.link.send_back(|_: ClickEvent| Msg::Click);
        html! {
            <button onclick=click_callback>
                { "Click me!" }
            </button>
        }
    }
}

will report 2 errors

The first error was very obvious, but I couldn't just &mut self. Because this will directly disrupt the library code.

The second error is contained in the macro, so I can't understand it.

By the way , sample code in the second tab Agent Handler seems have the same issue.

jstarry commented 4 years ago

Thanks for the report. This is my bad, the sample contains unreleased functionality. I will fix this evening

jstarry commented 4 years ago

Took me a month to fix.. 😅 v0.11 has been released and the sample code should work now