Function use_effect

Source
pub fn use_effect<G, D>(effect: impl FnOnce() -> G + 'static, deps: Deps<D>)
where G: IntoDestructor, 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({
  clones!(self.url, mut state);

  move || {
    state.set(|_| Some(fetch(url)));
  }
}, Deps::some(self.url));