Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/yew-macro/tests/hook_attr/hook-must-use-fail.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![deny(unused_must_use)]

use yew::prelude::*;

fn not_a_hook() {
use_effect_with((), |_| {});
}

fn main() {}
12 changes: 12 additions & 0 deletions packages/yew-macro/tests/hook_attr/hook-must-use-fail.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error: unused implementer of `Hook` that must be used
--> tests/hook_attr/hook-must-use-fail.rs:6:5
|
6 | use_effect_with((), |_| {});
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: hooks do nothing unless called inside a `#[hook]` or `#[component]` function
note: the lint level is defined here
--> tests/hook_attr/hook-must-use-fail.rs:1:9
|
1 | #![deny(unused_must_use)]
| ^^^^^^^^^^^^^^^
17 changes: 17 additions & 0 deletions packages/yew-macro/tests/hook_attr/hook-must-use-pass.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![deny(unused_must_use)]

use yew::prelude::*;

#[hook]
fn use_my_effect() {
use_effect_with((), |_| {});
}

#[component]
fn Comp() -> Html {
use_effect_with((), |_| {});
use_my_effect();
html! {}
}

fn main() {}
1 change: 1 addition & 0 deletions packages/yew/src/functional/hooks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::functional::HookContext;
/// Hooks are defined via the [`#[hook]`](crate::functional::hook) macro. It provides rewrites to
/// hook invocations and ensures that hooks can only be called at the top-level of a function
/// component or a hook. Please refer to its documentation on how to implement hooks.
#[must_use = "hooks do nothing unless called inside a `#[hook]` or `#[component]` function"]
pub trait Hook {
/// The return type when a hook is run.
type Output;
Expand Down
Loading