Skip to content

Commit ef6c599

Browse files
Update for wrappers pre.265
Fix useEffectOnce usage
1 parent f8d5666 commit ef6c599

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/jsMain/kotlin/App.kt

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import react.*
22
import react.dom.*
3-
import kotlinext.js.*
43
import kotlinx.html.js.*
54
import kotlinx.coroutines.*
65

76
private val scope = MainScope()
87

9-
val App = functionalComponent<RProps> { _ ->
8+
val App = fc<Props> {
109
val (shoppingList, setShoppingList) = useState(emptyList<ShoppingListItem>())
1110

12-
useEffect {
11+
useEffectOnce {
1312
scope.launch {
1413
setShoppingList(getShoppingList())
1514
}
@@ -32,16 +31,13 @@ val App = functionalComponent<RProps> { _ ->
3231
}
3332
}
3433
}
35-
child(
36-
InputComponent,
37-
props = jsObject {
38-
onSubmit = { input ->
39-
val cartItem = ShoppingListItem(input.replace("!", ""), input.count { it == '!' })
40-
scope.launch {
41-
addShoppingListItem(cartItem)
42-
setShoppingList(getShoppingList())
43-
}
34+
child(InputComponent) {
35+
attrs.onSubmit = { input ->
36+
val cartItem = ShoppingListItem(input.replace("!", ""), input.count { it == '!' })
37+
scope.launch {
38+
addShoppingListItem(cartItem)
39+
setShoppingList(getShoppingList())
4440
}
4541
}
46-
)
42+
}
4743
}

src/jsMain/kotlin/InputComponent.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import kotlinx.html.InputType
55
import org.w3c.dom.events.Event
66
import org.w3c.dom.HTMLInputElement
77

8-
external interface InputProps : RProps {
8+
external interface InputProps : Props {
99
var onSubmit: (String) -> Unit
1010
}
1111

12-
val InputComponent = functionalComponent<InputProps> { props ->
12+
val InputComponent = fc<InputProps> { props ->
1313
val (text, setText) = useState("")
1414

1515
val submitHandler: (Event) -> Unit = {

0 commit comments

Comments
 (0)