Lazycolumn and mutablestatelist

Android Jetpack Compose State

I have a list of borrowed books to show on the screen. When the title of a book is clicked, a dialog pops up and you can confirm the return of that book. What I want to do then is letting the title of the book disappear from the list.

Here is the process to do so:

  1. Click the return button which is found in a column of the LazyColumn
  2. It fires onClickBorrowedBook which remove the clicked book’s title from the borrowedBooksList
  3. As borrowedBooksList is a snapshotStateList and thus observable, the step 2 triggers a recomposition of the ReturnScreen.
fun ReturnScreen(
    borrowerState: State<BookBorrower>,
) {
    val borrowedBooksList = remember {
  /*Or, you can initialise this way:
  val borrowedBooksList2 = remember {
      mutableStateListOf<BorrowedBook>().apply { 
    LazyColumn {
		items = borrowedBooksList,
		itemContent = { borrowedBook ->
				borrowedBook = borrowedBook,
				onClickBorrowedBook = {
					val bookTitleToErase = borrowedBook.title
© 2023 Yasunari Kanemitsu