fix: key ViewModels to prevent incorrect re-use

This commit is contained in:
Harsh Shandilya 2025-05-29 23:45:37 +05:30
parent 931684f76b
commit bebbe4f82c
2 changed files with 2 additions and 2 deletions

View file

@ -36,7 +36,7 @@ fun CommentsPage(
contentPadding: PaddingValues, contentPadding: PaddingValues,
openUserProfile: (String) -> Unit, openUserProfile: (String) -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
viewModel: CommentsViewModel = injectedViewModel(), viewModel: CommentsViewModel = injectedViewModel(key = postId),
) { ) {
LaunchedEffect(postId) { viewModel.loadPostDetails(postId) } LaunchedEffect(postId) { viewModel.loadPostDetails(postId) }
val commentState by val commentState by

View file

@ -44,7 +44,7 @@ fun UserProfile(
contentPadding: PaddingValues, contentPadding: PaddingValues,
openUserProfile: (String) -> Unit, openUserProfile: (String) -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
viewModel: UserProfileViewModel = injectedViewModel(), viewModel: UserProfileViewModel = injectedViewModel(key = username),
) { ) {
LaunchedEffect(username) { viewModel.loadProfile(username) } LaunchedEffect(username) { viewModel.loadProfile(username) }
when (val state = viewModel.userProfile) { when (val state = viewModel.userProfile) {