collectModulePreviews

Returns a Lazy that provides the list of @Preview functions collected from this module only.

The Compose Preview Lab compiler plugin replaces the Lazy initializer at compile time with the actual list of CollectedPreview instances. If the compiler plugin is not applied, accessing the value throws an IllegalStateException.

The return type is Lazy so that @Composable lambdas inside CollectedPreview are initialized on first access rather than at class-load time, avoiding ExceptionInInitializerError.

Example — single-module preview collection:

val myPreviews by collectModulePreviews()

Example — used in a library module with public visibility:

// uiLib/src/commonMain/kotlin/Previews.kt
val uiLibPreviews by collectModulePreviews()

Return

a Lazy wrapping the collected preview list; the initializer is replaced by the compiler plugin

See also