How to call use_effect
?
#10
-
This is my attempt: use wasm_react::{
h,
hooks::{use_effect, use_state, Deps},
Component, VNode,
};
pub struct CanCamera;
impl Component for CanCamera {
fn render(&self) -> VNode {
use_state(|| false);
use_effect(|| println!("hi"), Deps::none());
h!(h1).build("can camera")
}
} but I get this error:
|
Beta Was this translation helpful? Give feedback.
Answered by
yishn
Nov 28, 2023
Replies: 2 comments
-
After looking at the example in use wasm_react::{
h,
hooks::{use_effect, use_state, Deps},
Component, VNode,
};
use web_sys::console::log_1;
pub struct CanCamera;
impl Component for CanCamera {
fn render(&self) -> VNode {
use_state(|| false);
use_effect(
{
log_1(&"use effect function!".into());
move || || ()
},
Deps::none(),
);
h!(h1).build("can camera")
}
} I'm guessing the |
Beta Was this translation helpful? Give feedback.
0 replies
-
You have to wrap your effect code in the closure and return a destructor (see also documentaiton): use_effect(move || {
log_1(&"...".into());
|| ()
}, Deps::none()); With v0.6 you do not need to return anything to imply a noop destructor use_effect(move || {
log_1(&"...".into());
}, Deps::none()); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ChocolateLoverRaj
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You have to wrap your effect code in the closure and return a destructor (see also documentaiton):
With v0.6 you do not need to return anything to imply a noop destructor
|| ()
: