# Sample Data in Compose Previews

DevFeed: [Sample Data in Compose Previews](<https://devfeed.tech/articles/sample-data-in-compose-previews-25973.md>)

Original publisher: [Read original article](<https://medium.com/snapp-mobile/sample-data-in-compose-previews-bec32b62370f?source=rss-8efc0359e234------2>)

Author: Jossi Wolf

Published: 2020-07-05T17:45:51Z

Content type: tutorial

Language: en

Sources: [Stories by Jossi Wolf on Medium](<https://devfeed.tech/sources/stories-by-jossi-wolf-on-medium.md>)

Topics: [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>), [Compose](<https://devfeed.tech/topics/compose.md>), [Android Studio](<https://devfeed.tech/topics/android-studio.md>), [Android](<https://devfeed.tech/topics/android.md>), [Design system](<https://devfeed.tech/topics/design-system.md>), [ui](<https://devfeed.tech/topics/ui.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-studio](<https://devfeed.tech/tags/android-studio.md>), [components](<https://devfeed.tech/tags/components.md>), [compose](<https://devfeed.tech/tags/compose.md>), [data](<https://devfeed.tech/tags/data.md>), [design-systems](<https://devfeed.tech/tags/design-systems.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [parameter](<https://devfeed.tech/tags/parameter.md>), [stories](<https://devfeed.tech/tags/stories.md>), [ui](<https://devfeed.tech/tags/ui.md>), [ui-components](<https://devfeed.tech/tags/ui-components.md>)

## AI overview

This tutorial explains how to provide sample data for Jetpack Compose previews using the @PreviewParameter annotation and PreviewParameterProvider. It addresses previews for parameterized Composables and lists, while noting that the annotation can be used on only one function parameter.

## Source excerpt

This post was written for Compose 0.1.0. Jetpack Compose is Google's new Android UI Toolkit, currently in development. If you already want to have a look, you can play around with it and learn some exciting new things! One area where Compose shines is previews. By annotating Composables with @Preview , you can preview the Composables inside Android Studio. This is very useful when working with e.g. Design Systems, or you just want to explore different variants of your UI components. But often, your Composables will take parameters, like our Project Composable. https://medium.com/media/9384b6a63c4a8ba376843a4ee3b90717/href In these cases, you can't use the Preview annotation on your Composable -- after all, Compose doesn't know where to obtain those parameters. One solution to this is to create "wrapper" Composables without any parameters. https://medium.com/media/d1f3459d8cd4af796160f696d97eb84d/href This has one big downside: You will end up creating lots of preview Composables, cluttering your code. In other cases, you might have a list and want to provide some sample data. With XML, supplying data for the preview was easily doable with the tools namespace. https://medium.com/media/16d547ae6a634bce91bb44023d4919e3/hrefPreviewParameter to the Rescue Luckily, Jetpack Compose has the @PreviewParameter annotation. It can be applied to any parameter of a @Preview. It needs PreviewParameterProvider , a simple interface which we can implement. https://medium.com/media/e1c92b209a2fdff94bb2a44662eee97f/href Finally, we can use the @Preview annotation with our @PreviewParameter -annotated arguments. https://medium.com/media/25d1c0eb02a8bfd7591af59dabce8885/href One caveat is that @PreviewParameter is only allowed on one parameter of a function, which is why we assign a default value to our second parameter. With this, previews become a lot more powerful in Compose. Let me know if this is useful in your day-to-day work and comment with any thoughts on this! Sample Data in Com