Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

126
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda