useRef

fun <T> ComponentScope.useRef(initializer: () -> T): Ref<T>

Declares a mutable, main-thread confined reference that will be persisted across renders with an initial value provided by the initializer. It's similar to useState, except that the returned reference is mutable and updating it will not cause a re-render.

IMPORTANT: It's only safe to read/write the Ref's value on the main thread!

An example of a safe way to use useRef is to store an Animator that is started/stopped from useEffect or a click event, both of which run on the UI thread.