Marc Knaup
11/16/2020, 6:49 PM@Suppress("unused")
fun RBuilder.useCoroutineScope(): CoroutineScope {
val (scope) = useState { CoroutineScope(GlobalScope.newCoroutineContext(Dispatchers.Unconfined)) }
useEffectWithCleanup(emptyList()) { { scope.cancel() } }
return scope
}
In component:
val scope = useCoroutineScope()
scope.launch { … }Rob Murdock
11/16/2020, 10:33 PMRob Murdock
11/16/2020, 10:33 PMJoost Klitsie
11/17/2020, 8:00 AMval cleanup: RCleanup = { scope.cancel() } outside of the useEffectWithCleanUp body, wouldn't that just recreate that function for nothing anytime useScope is called?Rob Murdock
11/17/2020, 1:42 PMMarc Knaup
11/17/2020, 1:44 PMJoost Klitsie
11/17/2020, 2:33 PM