Skip to main content

key

Function key 

Source
pub fn key<K: Hash, R>(keys: K, content: impl FnOnce() -> R) -> R
Expand description

Scopes composition identity to keys for the duration of content.

Mirrors Jetpack Compose’s key(vararg keys) { content }. A call keeps its identity by call-site position alone by default, so a slot survives a recomposition even when what a caller passes in changes; wrapping the call in key(keys, || ...) folds keys into that identity instead, so changing keys discards the previous state and starts fresh, and two key calls at the same call site with different keys never share state. Pass a tuple to key on more than one value, e.g. key((a, b), || ...).