xxfast
04/07/2026, 1:27 AMprivate val previewState = State()
// or
private val PreviewState = State()
According to coding convention,
Names of top-level or object properties which hold objects with behavior or mutable data should use camel case names:
val mutableCollection: MutableSet<String> = HashSet()
Names of properties holding references to singleton objects can use the same naming style asdeclarations:object
val PersonComparator: Comparator<Person> = /*...*/
For context - this is to be used in, for example
@Composable
fun Screen(state: State)
@Preview
@Composable
fun ScreenPreview() {
Screen(state = PreviewState)
}Matthew Feinberg
05/16/2026, 12:56 AMScreenState to avoid ambiguity with the built-in State type.
So... if ScreenState is an immutable data class, then it would make perfect sense to use UpperCamelCase like a singleton object. But if it were me, I'd probably make it a property on the companion object to avoid cluttering up the global namespace, and make it lazy to avoid allocating it when there's no preview:
data class ScreenState(.......etc...) {
companion object {
val PreviewState by Lazy { ScreenState() }
}
}
On the other hand, if ScreenState is mutable members, for example:
class ScreenState {
val something by mutableStateOf(......)
}
....then I would definitely not consider it a singleton, and I would lean away from using a share global var (because it could be mutated) and towards a factory function instead, like:
class ScreenState {
val something by mutableStateOf(......)
companion object {
fun makePreviewState(.....) = ScreenState(.....)
}
}
Hope that helps!
Also... #C0474L1Q8DR feels a bit dead these days, which is sad because I really like the idea.tumbleweed