I've one variable (paging data stream) that gets d...
# compose
r
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
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
    }
)
a
I’m not sure, but could this be a use case for
rememberUpdatedState
?
instead of the regular remember
r
Tried following but no luck
Copy code
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
    }
)