This commit is contained in:
coco
2026-07-15 16:57:36 +08:00
parent 723ce1af5c
commit 95aa018b8b
314 changed files with 8910 additions and 0 deletions
@@ -0,0 +1,17 @@
# CompositionLocalProvider
CompositionLocalProvider are used to provide a value for an [CompositionLocal](../compositionlocal)
## How to provide a value for an CompositionLocal?
```kotlin
@Composable
private fun MyUserScreen() {
val user = User("Jens", 31)
CompositionLocalProvider(LocalActiveUser provides user) {
UserInfo()
}
}
```
Somewhere above in your hierarchy you have to use CompositionLocalProviders to provide a value for your CompositionLocal. You can provide the values of multiple CompositionLocals inside Providers.
The syntax is: "**CompositionLocal`<T>`** provides **T**".
All child @Composable of CompositionLocalProvider will implicitly be able to get the value of the CompositionLocals.