Skip to content

use_effect

API

counterweight.hooks.use_effect

use_effect(setup: Setup, deps: Deps = None) -> None
PARAMETER DESCRIPTION
setup

The setup function that will be called when the component first mounts or if its dependencies have changed (see below).

TYPE: Setup

deps

The dependencies of the effect. If any of the dependencies change, the previous invocation of the setup function will be cancelled and the setup function will be run again. If None, the setup function will be run on every render.

TYPE: Deps DEFAULT: None

counterweight.hooks.Setup module-attribute

Setup = Callable[[], Coroutine[None, None, None]]

counterweight.hooks.Deps module-attribute

Deps = tuple[object, ...] | None

Effect Cancellation

Effects are cancelled by the framework when one of the following conditions is met:

  • The component that created the effect is unmounted.
  • The effect's dependencies change and the effect's setup function is going to be re-run.

Effect cancellation is synchronous

Note that the effect is synchronously cancelled (i.e., the Task that represents the effect is cancelled and then awaited; see this discussion) before the next render cycle starts. Assuming that you do not mess with the cancellation yourself from inside the effect setup function, the effect will definitely stop running before the next frame is rendered.