https://kotlinlang.org logo
#compose
Title
# compose
e

eygraber

02/01/2023, 4:29 AM
If I have a composable function
Foo
that returns a
Bar
and it gets called from
Baz
, if
Foo
needs to recompose does
Baz
recompose?
s

Stylianos Gakis

02/01/2023, 9:08 AM
Sounds like a yes. But you could probably throw some code here to make more clear what you are describing.
e

eygraber

02/01/2023, 9:15 AM
Yeah, quickly threw it out there because I was about to go to sleep 😅 I'm thinking something like
Copy code
@Composable
fun Foo(): Bar{
  return vm.barFlow().collectAsState().value
}

@Composable
fun Baz() {
  val bar = Foo()
  // do something with bar
}
s

Stylianos Gakis

02/01/2023, 9:45 AM
Yes, Baz will receive the new value from Foo(), and it will recompose. With that said, composable functions that return something should be lower-case to indicate that. So since your
Foo
returns a value, i should be called
foo
. Also it may be a good idea to return
State<Bar>
instead of doing the
value
read in the function itself, so that on the call site you can read it as a state and only use it later at the point that it is needed instead of the entire recomposition scope of
Baz
, but that’s a minute detail tbh.