1

I have a master-detail app for android using kotlin and jetpack compose components. The flow in the app should be:

  1. Open app
  2. The app starts in the master view with a list having all items that were retrieved from a api using a view model.
  3. When an item is clicked, we navigate towards the detail screen which should call only once findItem(id) function which is implemented in the view model of the screen.

The problem is that I don t know how to call only at the first render the function from the view model. Right now , there is an infinite loop inside which the find function is called because I store the item provided by the view model inside an observableState. Every time that changes, the component is rerendered and the find function is called again. How can I call it only once?

1 Answers1

3
LaunchedEffect(Unit) {
    // this will run once per composition 
}
Jakoss
  • 4,647
  • 2
  • 26
  • 40