Skip to content
Discussion options

You must be logged in to vote

Hooks can only be used in the following locations:

  • Top-level of a function/hook.
  • Blocks inside a function/hook, given it is not already branched.
  • In the condition of a top-level if expression inside a function/hook.
  • In the scrutinee of a top-level match expression inside a function/hook.

I agree this is a bit misleading.
All functions above actually mean "function component"

alternatively you can make this work by making load_videos a custom hook with the "hook" attribute:

#[hook]
fn use_load_videos(videos: UseStateHandle<Vec<Video>>) {
    use_effect_with((), move |_| {
        set_videos(videos);
        || ()
    });
}

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@gjgiezeman
Comment options

Answer selected by gjgiezeman
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants