From c3403681e295dc9d426e4d6d8f544f13e0a59030 Mon Sep 17 00:00:00 2001 From: Oleksandr Karpovich Date: Mon, 31 May 2021 12:03:47 +0200 Subject: [PATCH] Update `web-getting-started` example and tutorial --- .../web-getting-started/src/jsMain/kotlin/Main.kt | 11 ++++++----- tutorials/Web/Getting_Started/README.md | 7 +++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/examples/web-getting-started/src/jsMain/kotlin/Main.kt b/examples/web-getting-started/src/jsMain/kotlin/Main.kt index 77623ae647..bfe45f90cd 100644 --- a/examples/web-getting-started/src/jsMain/kotlin/Main.kt +++ b/examples/web-getting-started/src/jsMain/kotlin/Main.kt @@ -1,4 +1,6 @@ import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.getValue +import androidx.compose.runtime.setValue import androidx.compose.web.css.padding import androidx.compose.web.css.px import androidx.compose.web.elements.Button @@ -8,23 +10,22 @@ import androidx.compose.web.elements.Text import androidx.compose.web.renderComposable fun main() { - val count = mutableStateOf(0) + var count: Int by mutableStateOf(0) renderComposable(rootElementId = "root") { Div(style = { padding(25.px) }) { Button(attrs = { - onClick { count.value = count.value - 1 } + onClick { count -= 1 } }) { Text("-") } Span(style = { padding(15.px) }) { - Text("${count.value}") + Text("$count") } - Button(attrs = { - onClick { count.value = count.value + 1 } + onClick { count += 1 } }) { Text("+") } diff --git a/tutorials/Web/Getting_Started/README.md b/tutorials/Web/Getting_Started/README.md index 0d2ea0b3d7..ff157adbfa 100644 --- a/tutorials/Web/Getting_Started/README.md +++ b/tutorials/Web/Getting_Started/README.md @@ -115,6 +115,13 @@ fun main() { } } ``` +In case you see an error: +`Type 'MutableState' has no method 'getValue(Nothing?, KProperty<*>)'...` or +`Type 'MutableState' has no method 'setValue(Nothing?, KProperty<*>, Int)'...`, please add the imports: +```kotlin +import androidx.compose.runtime.getValue +import androidx.compose.runtime.setValue +``` ## Running the project