I've one variable (paging data stream) that gets data from view model based on some input id. This data should only arrived when user click on certain button, else data would be empty. How can i make sure that this data comes from view model when user click on button and provide that input id. code is in thread
rajesh
08/26/2021, 4:35 PM
Tried following, but not working, it change variable value, but not triggering data from view model
Copy code
var postId by remember { mutableStateOf<Long?>(null) }
val comments =
remember(commentViewModel) { commentViewModel.getPostComments(postId) }.collectAsLazyPagingItems()
MyFuncion(
onClick { id ->
postId = id
}
)
var id by remember { mutableStateOf<Long?>(null) }
var postId = rememberUpdatedState(newValue = id)
val comments =
remember(commentViewModel) { commentViewModel.getPostComments(postId.value) }.collectAsLazyPagingItems()
MyFuncion(
onClick { newId->
id = newId
}
)