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 in struct component #45

Closed MhhhxX closed 1 month ago

MhhhxX commented 1 month ago

Using the async hook inside a struct component produces the following error when calling the run function:

error[E0061]: this method takes 1 argument but 0 arguments were supplied
  --> src/app/components.rs:38:15
   |
38 |             p.run();
   |               ^^^-- argument #1 of type `&mut HookContext` is missing
   |
note: method defined here
  --> /.cargo/registry/src/index.crates.io-6f17d22bba15001f/yew-0.21.0/src/functional/hooks/mod.rs:35:8
   |
35 |     fn run(self, ctx: &mut HookContext) -> Self::Output;
   |        ^^^
help: provide the argument
   |
38 |             p.run(/* &mut HookContext */);
   |                  ~~~~~~~~~~~~~~~~~~~~~~~~

How can I provide the hook context here?

jetli commented 1 month ago

Hooks in yew can only support function components, you cannot use them in struct component.