Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,13 @@ this.lifecycleScope.launch {
- What are the best practices for performance optimization in Jetpack Compose?
- How is navigation handled in Jetpack Compose?
- What is Strong Skipping Mode? [Answer](https://www.linkedin.com/posts/anandwana001_coding-datastructures-jetpackcompose-activity-7193437801365823488-SlVT?utm_source=share&utm_medium=member_desktop)
- Compare and contrast `LaunchedEffect`, `SideEffect`, and `DisposableEffect`. Provide a clear use case for each one.
- `LaunchedEffect` is used to run a suspend function (coroutine) safely from a composable. It launches when the composable first enters the composition and cancels when it leaves. It will relaunch if its `key` parameter changes.
Use Case is to run a one-time suspend action when the composable first enters the composition, such as fetching initial data from a network or showing a `Snackbar`
- SideEffect is used to execute a block of code after every successful recomposition. It's an escape hatch to share Compose state with non-Compose code.
Use Case is to publish Compose state to non-Compose code, for example, updating an analytics library with the latest state value after every recomposition.
- `DisposableEffect` is similar to `LaunchedEffect` but provides a mandatory `onDispose` block for cleanup. The onDispose block is executed when the composable leaves the composition or when the `key` changes.
Use Case is to manage resources that require explicit cleanup, such as registering a `LifecycleObserver` and ensuring it's unregistered in the `onDispose` block to prevent memory leaks.


## Thread
Expand Down