-
Notifications
You must be signed in to change notification settings - Fork 11.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Makes effects in composables more declarative #878
base: main
Are you sure you want to change the base?
Conversation
LaunchedEffect(uiState.isTaskSaved) { | ||
if (uiState.isTaskSaved) { | ||
onTaskUpdate() | ||
if (uiState.isTaskSaved) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this run on every recomposition, regardless of if uiState.isTaskSaved
changed or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is answered here: https://stackoverflow.com/questions/69085027/difference-between-remember-and-rememberupdatedstate-in-jetpack-compose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. This if statement will be check on every recomposition
LaunchedEffect(uiState.isTaskSaved) { | ||
if (uiState.isTaskSaved) { | ||
onTaskUpdate() | ||
if (uiState.isTaskSaved) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is using recomposition as an observer of state change events to apply other changes to app state. Avoid this. Observe the state changes inside the LaunchedEffect
instead so that it doesn't take one recomposition pass to apply currentOnTaskUpdate
and then another to apply changes caused by that call.
No description provided.