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 11import react.*
22import react.dom.*
3- import kotlinext.js.*
43import kotlinx.html.js.*
54import kotlinx.coroutines.*
65
76private 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}
Original file line number Diff line number Diff line change @@ -5,11 +5,11 @@ import kotlinx.html.InputType
55import org.w3c.dom.events.Event
66import 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 = {
You can’t perform that action at this time.
0 commit comments