useEffect

fun ComponentScope.useEffect(vararg deps: Any?, onAttach: () -> CleanupFunc?)

Registers a callback to perform side-effects when this Component is attached/detached from the tree.

The onAttach callback will be invoked when the owning Component first becomes part of a committed layout on the ComponentTree on the main thread. It should return a CleanupFunc callback to be invoked when the owning Component is detached, e.g. the ComponentTree is released or the Component is no longer part of the tree.

Additionally, any time the list of deps changes between layouts, the existing onAttach's cleanup callback will be invoked, and the new onAttach callback will be invoked.

deps should contain any props or state your attach/cleanup callbacks use. For example, if you're using useEffect to subscribe to a data store based on an id you get as a prop, deps should include that id so that if the id changes, we will unsubscribe from the old id and subscribe with the new id.


fun ComponentScope.useEffect(onAttach: () -> CleanupFunc?)

Deprecated (with error)

useEffect must provide 'deps' parameter that determines whether the existing 'onAttach' cleanup callback will be invoked, and the new 'onAttach' callback will be invoked

Registers a callback to perform side-effects when this Component is attached/detached from the tree.

It is an error to call ComponentScope.useEffect without deps parameter.