Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expected a Fn<(MouseEvent,)> closure, found Callback<&yew::Event> #2663

Closed
jasper2007111 opened this issue May 6, 2022 · 0 comments
Closed
Labels

Comments

@jasper2007111
Copy link

fn view(&self, ctx: &Context<Self>) -> Html {
        let history = ctx.link().navigator().unwrap();
        let onclick = Callback::from(move |_| history.push(Route::Add));

        let history1 = ctx.link().navigator().unwrap();
        let on_edit_click = Callback::from(move |event: &Event| {
            history1.push(Route::Edit);
        });

        match &self.todo {
            FetchState::NotFetching => html! {
                <>
                    <button onclick={ctx.link().callback(|_| Msg::GetTodo)}>
                        { "Get Markdown" }
                    </button>
                    <button onclick={ctx.link().callback(|_| Msg::GetError)}>
                        { "Get using incorrect URL" }
                    </button>
                </>
            },
            FetchState::Fetching => html! { "Fetching" },
            FetchState::Success(data) => || -> Html {
                html! {
                    <div>
                        <h1>{ "记事本" }</h1>
                        <div>
                        {
                            data.into_iter().map(|note| {
                                html!{
                                    <div style="margin: 10px 10px 0 0;">
                                    <div>{note.content.clone()}</div>
                                    <div>{note.create_time.clone()}</div>
                                    <button onclick={on_edit_click}>{"编辑"}</button>
                                    </div>
                                }
                            }).collect::<Html>()
                        }
                        </div>
                        <div style="margin: 10px 10px 0 0;"><button {onclick}>{ "添加" }</button></div>
                    </div>
                }
            }(),
            FetchState::Failed(err) => html! { err },
        }
    }
error[E0277]: expected a `Fn<(MouseEvent,)>` closure, found `Callback<&yew::Event>`
   --> src/jasper_ji/home.rs:146:54
    |
142 | / ...                   html!{
143 | | ...                       <div style="margin: 10px 10px 0 0;">
144 | | ...                       <div>{note.content.clone()}</div>
145 | | ...                       <div>{note.create_time.clone()}</div>
146 | | ...                       <button onclick={on_edit_click}>{"编辑"}</button>
    | |                                            ^^^^^^^^^^^^^ expected an `Fn<(MouseEvent,)>` closure, found `Callback<&yew::Event>`
147 | | ...                       </div>
148 | | ...                   }
    | |_______________________- required by a bound introduced by this call
    |
    = help: the trait `Fn<(MouseEvent,)>` is not implemented for `Callback<&yew::Event>`
    = note: required because of the requirements on the impl of `IntoEventCallback<MouseEvent>` for `Callback<&yew::Event>`
note: required by a bound in `yew::html::onclick::Wrapper::__macro_new`
   --> /Users/jasperji/.cargo/git/checkouts/yew-7424ad4d701b481c/c28a71e/packages/yew/src/html/listener/events.rs:129:1
    |
129 | / impl_short! {
130 | |     onauxclick(MouseEvent)
131 | |     onclick(MouseEvent)
132 | |
...   |
193 | |     ontransitionstart(TransitionEvent)
194 | | }
    | |_^ required by this bound in `yew::html::onclick::Wrapper::__macro_new`
    = note: this error originates in the macro `impl_action` (in Nightly builds, run with -Z macro-backtrace for more info)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant