mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 16:27:06 +05:30
android: avoid coroutine launch in composition context
This commit is contained in:
parent
cfd0725605
commit
53905c80de
1 changed files with 2 additions and 4 deletions
|
@ -4,10 +4,10 @@ import androidx.compose.foundation.layout.padding
|
|||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
@ -18,7 +18,6 @@ import dev.msfjarvis.claw.common.posts.PostActions
|
|||
import dev.msfjarvis.claw.common.posts.toDbModel
|
||||
import dev.msfjarvis.claw.database.local.SavedPost
|
||||
import dev.msfjarvis.claw.model.LobstersPost
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun NetworkPosts(
|
||||
|
@ -28,7 +27,6 @@ fun NetworkPosts(
|
|||
postActions: PostActions,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
LazyColumn(
|
||||
state = listState,
|
||||
modifier = modifier,
|
||||
|
@ -37,7 +35,7 @@ fun NetworkPosts(
|
|||
if (item != null) {
|
||||
val dbModel = item.toDbModel()
|
||||
var saved by remember(dbModel) { mutableStateOf(false) }
|
||||
coroutineScope.launch { saved = isSaved(dbModel) }
|
||||
LaunchedEffect(dbModel) { saved = isSaved(dbModel) }
|
||||
LobstersCard(
|
||||
post = dbModel,
|
||||
isSaved = saved,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue