There was an error while loading. Please reload this page.
useEffectWithCleanup
1 parent 57ca268 commit 1ad09f4Copy full SHA for 1ad09f4
src/main/kotlin/hook/useEffectWithCleanup.kt
src/main/kotlin/hook/useUsers.kt
@@ -5,16 +5,17 @@ import kotlinx.browser.window
5
import kotlinx.coroutines.GlobalScope
6
import kotlinx.coroutines.await
7
import kotlinx.coroutines.launch
8
+import react.useEffect
9
import react.useState
10
11
fun useUsers(): Users {
12
var data by useState<Users>(emptyArray())
13
- useEffectWithCleanup {
14
+ useEffect {
15
val job = GlobalScope.launch {
16
data = getUsers()
17
}
- job::cancel
18
+ cleanup(job::cancel)
19
20
21
return data
0 commit comments