# Leveraging @RequireOptIn to create composables that can be used only in previews

DevFeed: [Leveraging @RequireOptIn to create composables that can be used only in previews](<https://devfeed.tech/articles/leveraging-requireoptin-to-create-composables-that-can-be-used-only-in-previews-28722.md>)

Original publisher: [Read original article](<https://le0nidas.gr/2026/03/22/leveraging-requireoptin-to-create-composables-that-can-be-used-only-in-previews/>)

Author: Leonidas Partsas

Published: 2026-03-22T14:32:15Z

Content type: tutorial

Language: en

Sources: [le0nidas](<https://devfeed.tech/sources/le0nidas.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [compilation-error](<https://devfeed.tech/tags/compilation-error.md>), [components](<https://devfeed.tech/tags/components.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [know-your-tools](<https://devfeed.tech/tags/know-your-tools.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [module](<https://devfeed.tech/tags/module.md>), [preview](<https://devfeed.tech/tags/preview.md>), [production](<https://devfeed.tech/tags/production.md>), [requireoptin](<https://devfeed.tech/tags/requireoptin.md>)

## AI overview

This tutorial explains how to use Kotlin's @RequiresOptIn mechanism with a @PreviewOnly annotation to expose composables for preview rendering across modules while preventing their use in production code. Explicit opt-in is required at each call site, otherwise compilation fails.

## Source excerpt

Anyone working with Kotlin, especially in the android world, has dealt with RequireOptIn. Actually they had to deal with the consequence of its application which is to explicitly opt-in into using a piece of code that is annotated with it. @RequiresOptIn In a nutshell, if you want the consumer of your code to be fully ... Continue reading Leveraging @RequireOptIn to create composables that can be used only in previews ->