Compose State Slots & Content Lambdas
Make components flexible with slot APIs.
Compose State Slots & Content Lambdas is a free Jetpack Compose Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Jetpack Compose Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Make Components Flexible
A slot lets a component accept a chunk of UI as a parameter. The caller fills the slot, so one component fits many designs.
Meet the content Lambda
The most common slot is a trailing content lambda of type @Composable () -> Unit. Whatever you put in braces becomes the body.
fun Card(content: @Composable () -> Unit) {
Surface { content() }
}Calling a Slot
You call the slot just like a normal lambda. Compose runs whatever UI the caller passed, right where you invoke content().
Card {
Text("Anything I want lives here")
}Why Slots Beat Booleans
Instead of many flags like showIcon or showTitle, expose slots. Callers compose exactly what they need, with full freedom.
Named Slots
Components can offer several slots, each a parameter. Scaffold does this with topBar, bottomBar, and content. 🧩
fun Banner(
title: @Composable () -> Unit,
action: @Composable () -> Unit
) { /* lay them out */ }Scopes Add Power
A slot can be a receiver lambda, giving the caller helpers. Inside a Column, content is ColumnScope.() -> Unit so weight works.
fun MyColumn(content: @Composable ColumnScope.() -> Unit) {
Column { content() }
}Passing Data Into a Slot
Slots can hand values to the caller. A list row slot might pass the item so the caller decides how to draw it.
fun Row(item: User, content: @Composable (User) -> Unit) {
content(item)
}Slots Keep State Hoisted
Because the caller supplies the slot content, your component stays stateless about what is inside it. Ownership stays clear.
Reuse Across Screens
One Card or Dialog with slots replaces a dozen near-identical components. You build the frame once and vary the filling. ♻️
Default Slot Content
Give a slot a sensible default so simple callers can skip it, while advanced callers override it fully.
fun Section(
header: @Composable () -> Unit = { Text("Section") },
content: @Composable () -> Unit
) { /* ... */ }The Slot Mindset
When a component starts collecting boolean flags, reach for slots instead. Flexibility comes from passing UI, not toggles.
Quick Check
What is the main benefit of a content slot lambda?
Recap
Slots accept UI as @Composable lambdas, optionally scoped or passing data. They make components flexible while keeping state hoisted. 🚀
Frequently asked questions
Is the “Compose State Slots & Content Lambdas” lesson free?
Yes — the full text of “Compose State Slots & Content Lambdas” is free to read here on the web, and the Jetpack Compose Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Jetpack Compose Academy course, upgrade to CoddyKit PRO.
What will I learn in “Compose State Slots & Content Lambdas”?
Make components flexible with slot APIs. You practise Jetpack Compose Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Jetpack Compose Academy?
No prior experience is required. Jetpack Compose Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Compose State Slots & Content Lambdas” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Jetpack Compose Academy lesson?
Yes. Every Jetpack Compose Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Stateful vs Stateless Composables
- Hoist State with value & onValueChange
- Single Source of Truth
- Compose State Slots & Content Lambdas