Extract Reusable Composables
Refactor the screen into clean components.
Extract Reusable Composables 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.
Time to Refactor
Your card works, but it is one long function. Now you will split it into small, named Composables that are easier to read and reuse. 🧩
Spot Repeated Patterns
The three stat blocks are nearly identical. Repeated shapes like that are a strong signal to extract a single reusable Composable.
Extract StatBlock
Pull one stat into its own function. Pass the differing values, the count and label, in as parameters.
@Composable
fun StatBlock(count: String, label: String) {
Column { Text(count); Text(label) }
}Reuse It Three Times
Now the stats Row is just three clean calls. The same StatBlock renders different data each time, with zero duplication.
Row {
StatBlock("128", "Posts")
StatBlock("4.2k", "Followers")
StatBlock("180", "Following")
}Extract the Header
Group the avatar, name, and bio into a ProfileHeader Composable. The big screen function gets shorter and far easier to scan.
@Composable
fun ProfileHeader(name: String, bio: String) {
Column { /* avatar, name, bio */ }
}Name Things Clearly
Good Composable names describe what you see: ProfileHeader, StatBlock, FollowButton. Clear names make the card read like a sentence.
Pass Data In
Keep components flexible by accepting parameters instead of hard-coding values. The same ProfileHeader can show any user.
ProfileHeader(name = "Ada Lovelace", bio = "Building apps.")Hoist the Click Out
Let the parent decide what a tap does. Expose an onFollowClick lambda parameter so FollowButton stays generic.
@Composable
fun FollowButton(onClick: () -> Unit) {
Button(onClick = onClick) { Text("Follow") }
}Assemble the Screen
The top-level ProfileCard now just composes the pieces in order. Each child Composable owns one job, which is the Compose way.
Column {
ProfileHeader(name, bio)
StatsRow(stats)
FollowButton(onFollow)
}Add a Modifier Parameter
Truly reusable Composables accept a Modifier parameter, defaulting to Modifier. Callers can then size and pad them from outside.
@Composable
fun StatBlock(
count: String,
label: String,
modifier: Modifier = Modifier
) { /* ... */ }Clean and Reusable
Your one giant function is now several small, focused, reusable Composables. This structure scales as your app grows in complexity. 🎉
Quick Check
What makes a Composable reusable across different data?
Recap: You Shipped a Card
You refactored the profile card into small reusable Composables with parameters and a Modifier slot. You now have a clean, scalable screen built end to end.
Frequently asked questions
Is the “Extract Reusable Composables” lesson free?
Yes — the full text of “Extract Reusable Composables” 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 “Extract Reusable Composables”?
Refactor the screen into clean components. 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 “Extract Reusable Composables” 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
- Sketch the Profile Card Layout
- Avatar, Name & Bio Section
- Stats Row & Follow Button
- Extract Reusable Composables