jetli / yew-hooks

Hooks for Yew, inspired by streamich/react-use and alibaba/hooks.
https://jetli.github.io/yew-hooks/
Apache License 2.0
169 stars 13 forks source link

use_async error (the trait bound `impl yew::functional::hooks::Hook<Output = UseAsyncHandle<_, _>> + '_: Hook` is not satisfied) #36

Closed nocl1p closed 1 year ago

nocl1p commented 1 year ago

I can't get what's the problem with trait bound when I try to use use_async hook:

let current_user = use_async(async move { api_users_me().await });

API function is

pub async fn api_users_me() -> Result<UserData, RequestError> {
    request_get::<UserData>("/api/users/me".to_string()).await
}

I get this error

error[E0277]: the trait bound `impl yew::functional::hooks::Hook<Output = UseAsyncHandle<UserData, RequestError>> + '_: Hook` is not satisfied
  --> src/client/user_context_provider.rs:20:21
   |
20 |     let current_user = use_async(async move { api_users_me().await });
   |                        ---------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |                        |
   |                        the trait `Hook` is not implemented for `impl yew::functional::hooks::Hook<Output = UseAsyncHandle<UserData, RequestError>> + '_`
   |                        required by a bound introduced by this call
   |
   = help: the trait `Hook` is implemented for `BoxedHook<'_, T>`
nocl1p commented 1 year ago

I'm just trying use yew-hooks with yew ssr. Seems like it's not so simple