How do I prevent `PlotColors` being recreated on e...
# compose
d
How do I prevent
PlotColors
being recreated on each composable function call here? I can't put this in "remember", because
MyTheme.colors.someColor
is a
Composable
getter:
Copy code
fun MyComposable() {
  val colors = PlotColors(
    positiveColor = MyTheme.colors.indicatorContentGreen,
    negativeColor = MyTheme.colors.indicatorBackgroundRed,
  )
}
Oh. I suppose I could do
Copy code
val positiveColor = MyTheme.colors.indicatorContentGreen,
  val negativeColor = MyTheme.colors.indicatorContentGreen,
  val colors by remember { PlotColors(positiveColor, negativeColor) }
but that would get very verbose in presence of many colors
c
Seems to be an unnecessary optimisation. You end up creating a lot more objects when using compose anyways. Compose will skip recomposition if your input does not change.
d
Thought so too, asked just in case I sometime will need something like this in a performance critical path with a lot of updates.
c
If you have expensive calculations, you can use
derivedStateOf