---
title: "ProvidableCompositionLocal"
description: "A [ProvidableCompositionLocal] can be used in [CompositionLocalProvider] to provide values."
type: "class"
---

<div class='type'>Class</div>


<a id='references'></a>

<div class='sourceset sourceset-common'>Common</div>


```kotlin
public abstract class ProvidableCompositionLocal<T> internal constructor(defaultFactory: () -> T) :
    CompositionLocal<T>(defaultFactory)
```


A `ProvidableCompositionLocal` can be used in `CompositionLocalProvider` to provide values.


## Functions

```kotlin
public infix fun provides(value: T): ProvidedValue<T>
```


Associates a `CompositionLocal` key to a value in a call to `CompositionLocalProvider`.


```kotlin
public infix fun providesDefault(value: T): ProvidedValue<T>
```


Associates a `CompositionLocal` key to a value in a call to `CompositionLocalProvider` if the
key does not already have an associated value.


```kotlin
public infix fun providesComputed(
        compute: CompositionLocalAccessorScope.() -> T
    ): ProvidedValue<T>
```


Associates a `CompositionLocal` key to a lambda, `compute`, in a call to `CompositionLocal`.
The `compute` lambda is invoked whenever the key is retrieved. The lambda is executed in the
context of a `CompositionLocalContext` which allow retrieving the current values of other
composition locals by calling `CompositionLocalAccessorScope.currentValue`, which is an
extension function provided by the context for a `CompositionLocal` key.

The lambda passed to `providesComputed` will be invoked every time the
`CompositionLocal.current` is evaluated for the composition local and computes its value
based on the current value of the locals referenced in the lambda at the time
`CompositionLocal.current` is evaluated. This allows providing values that can be derived
from other locals. For example, if accent colors can be calculated from a single base color,
the accent colors can be provided as computed composition locals. Providing a new base color
would automatically update all the accent colors.



