Function wasm_react::hooks::use_effect
source · [−]pub fn use_effect<G, D>(effect: impl FnOnce() -> G + 'static, deps: Deps<D>) where
G: FnOnce() + 'static,
D: PartialEq + 'static,
Expand description
Runs a function which contains imperative code that may cause side-effects.
The given function will run after render is committed to the screen when the given dependencies have changed from last render. The function can return a clean-up function.
Example
let state = use_state(|| None);
use_effect({
let mut state = state.clone();
let url = self.url;
move || {
state.set(|_| Some(fetch(url)));
|| ()
}
}, Deps::some(self.url));