Member-only story
Composition Local In Jetpack Compose.
In this article we will see Composition Local
in Jetpack Compose and also see when to use or not.
If I asked a question to you , how do you pass any data to child composable functions?
Well your answer will be , pass data in the child’s composable function parameter, That’s it .
But if i say, now you don’t need to pass any data explicitly in the child composable function parameter instead of that use Composition Local
.
So what Composition Local
does , without passing anything in the function parameter , you can use that object directly in the child composable function.
Predefined Composition Locals
Jetpack Compose provides multiple predefined composition Locals implementations that start with the word Local
.
The most popular or you heard is -
val context = LocalContext.current
here LocalContext
is a Composition Local which find the context of current screen through .current
.