key

inline fun <T> key(vararg inputs: Any?, block: () -> T): T

key is a utility composable that is used to "group" or "key" a block of execution inside of a composition. This is sometimes needed for correctness inside of control-flow that may cause a given composable invocation to execute more than once during composition.

The value for a key does not need to be globally unique, and needs only be unique amongst the invocations of keyat that point in composition.

For instance, consider the following example:

Samples

androidx.compose.runtime.samples.LocallyUniqueKeysandroidx.compose.runtime.samples.MoreCorrectUniqueKeysandroidx.compose.runtime.samples.NotAlwaysUniqueKeysandroidx.compose.runtime.samples.TwoInputsKeySample

Parameters

block

The composable children for this group.

inputs

The set of values to be used to create a compound key. These will be compared to their previous values using equals and hashCode