Member-only story

Composition Local In Jetpack Compose.

Jayant Kumar🇮🇳
4 min readSep 26, 2023

--

Photo by Elaine Casap on Unsplash

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 .

--

--

Jayant Kumar🇮🇳
Jayant Kumar🇮🇳

Written by Jayant Kumar🇮🇳

Hello My name is Jayant Kumar, I am a software Engineer , specialist in Mobile Development (Android , IOS , Flutter , React Native and Ionic) from India 🇮🇳

Responses (1)