File tree Expand file tree Collapse file tree 2 files changed +11
-15
lines changed Expand file tree Collapse file tree 2 files changed +11
-15
lines changed Original file line number Diff line number Diff line change 1
1
import react.*
2
2
import react.dom.*
3
- import kotlinext.js.*
4
3
import kotlinx.html.js.*
5
4
import kotlinx.coroutines.*
6
5
7
6
private val scope = MainScope ()
8
7
9
- val App = functionalComponent< RProps > { _ ->
8
+ val App = fc< Props > {
10
9
val (shoppingList, setShoppingList) = useState(emptyList<ShoppingListItem >())
11
10
12
- useEffect {
11
+ useEffectOnce {
13
12
scope.launch {
14
13
setShoppingList(getShoppingList())
15
14
}
@@ -32,16 +31,13 @@ val App = functionalComponent<RProps> { _ ->
32
31
}
33
32
}
34
33
}
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())
44
40
}
45
41
}
46
- )
42
+ }
47
43
}
Original file line number Diff line number Diff line change @@ -5,11 +5,11 @@ import kotlinx.html.InputType
5
5
import org.w3c.dom.events.Event
6
6
import org.w3c.dom.HTMLInputElement
7
7
8
- external interface InputProps : RProps {
8
+ external interface InputProps : Props {
9
9
var onSubmit: (String ) -> Unit
10
10
}
11
11
12
- val InputComponent = functionalComponent <InputProps > { props ->
12
+ val InputComponent = fc <InputProps > { props ->
13
13
val (text, setText) = useState(" " )
14
14
15
15
val submitHandler: (Event ) -> Unit = {
You can’t perform that action at this time.
0 commit comments