diff --git a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskScreen.kt b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskScreen.kt index 4fa419a2a..96d2ae89a 100644 --- a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskScreen.kt +++ b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/addedittask/AddEditTaskScreen.kt @@ -38,6 +38,7 @@ import androidx.compose.material.rememberScaffoldState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue +import androidx.compose.runtime.rememberUpdatedState import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.dimensionResource @@ -84,9 +85,10 @@ fun AddEditTaskScreen( ) // Check if the task is saved and call onTaskUpdate event - LaunchedEffect(uiState.isTaskSaved) { - if (uiState.isTaskSaved) { - onTaskUpdate() + if (uiState.isTaskSaved) { + val currentOnTaskUpdate by rememberUpdatedState(onTaskUpdate) + LaunchedEffect(Unit) { + currentOnTaskUpdate() } } diff --git a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/taskdetail/TaskDetailScreen.kt b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/taskdetail/TaskDetailScreen.kt index 47532ad5c..e35d6bb7d 100644 --- a/app/src/main/java/com/example/android/architecture/blueprints/todoapp/taskdetail/TaskDetailScreen.kt +++ b/app/src/main/java/com/example/android/architecture/blueprints/todoapp/taskdetail/TaskDetailScreen.kt @@ -36,6 +36,7 @@ import androidx.compose.material.rememberScaffoldState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue +import androidx.compose.runtime.rememberUpdatedState import androidx.compose.ui.Modifier import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.stringResource @@ -92,9 +93,10 @@ fun TaskDetailScreen( } // Check if the task is deleted and call onDeleteTask - LaunchedEffect(uiState.isTaskDeleted) { - if (uiState.isTaskDeleted) { - onDeleteTask() + if (uiState.isTaskDeleted) { + val currentOnDeleteTask by rememberUpdatedState(onDeleteTask) + LaunchedEffect(Unit) { + currentOnDeleteTask() } } }