Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
Is it ok to pass a Flow from one composable to another?

I have a view model which exposes a flow of events. I have that viewModel injected in a top level composable but I want to send the events to another composable (inside the top level composable). Something like this:

@Composable
fun MainScreen(viewModel: MyViewModel) {
    SomeComponent(viewModel.events) 
    // Other Stuff   
}

@Composable
fun SomeComponent(events: Flow<MyEvent>) { // MyEvent is a sealed class
    LaunchedEffect(Unit) {
        events.collect {
            // Process the events
        }
    }
    // Other stuff
}

The reason I am collecting the flow in SomeComponent and not MainScreen is because I need access to some internal state of SomeComponent (it's a ScaffoldState actually) for processing the events.

I wrote this code in my app and everything seems to be working but I am not sure if this is a good thing to do.
My question is:
Are there any drawbacks in this approach that I missed? What can possibly go wrong here?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Passing a flow as parameter is fine. There is nothing special about a flow. It's just another data source like anything else. If you didn't pass it in, you would have to come up with some other way of accessing it and that would probably result in breaking the uni-directional flow pattern that Composables should adhere to.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!