i have another question regarding using `observeAs...
# compose
j
i have another question regarding using
observeAsState()
to automatically populate a composable list view. My composable looks like this
Copy code
@Composable
    fun getTopMovies() {
        val topMovies by movieListViewModel.getTopMovies().observeAsState()
        when (topMovies?.status) {
            Status.Error -> Text("error")
            Status.Loading -> {
                Log.d("JJJ", "Loading ")
                Text(text = "Loading")
            }
            Status.Success -> createMovieItemView(topMovies?.data?.results.orEmpty())
        }
    }
This uses MVVM to do a network call to fetch some list of data and return it it back as a livedata. The issue i am having is that it seems stuck on a infinit loop. If i dont use
observeeAsState
and just use the normal none composable way ie
movieListViewModel.getTopMovies().observe(viewLifecycleOwner, Observer {
it works as expected and executes and ends once a error or a success is returned from the repository/domain layer. This is the
createMovieItemView
below:
Copy code
@Composable
    private fun createMovieItemView(movieList: List<MovieItem>) {
        LazyColumnFor(items = movieList, itemContent = { movieItem ->
            MovieListItem(MovieItemData(movieItem.posterPath.orEmpty(),
                    movieItem.title.orEmpty(),
                    movieItem.releaseDate.orEmpty(),
                    "some genra", ""), picasso)

        })
    }