Skip to content
Snippets Groups Projects
Commit c3403681 authored by Oleksandr Karpovich's avatar Oleksandr Karpovich
Browse files

Update `web-getting-started` example and tutorial

parent f54a4b96
No related branches found
No related tags found
No related merge requests found
import androidx.compose.runtime.mutableStateOf 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.padding
import androidx.compose.web.css.px import androidx.compose.web.css.px
import androidx.compose.web.elements.Button import androidx.compose.web.elements.Button
...@@ -8,23 +10,22 @@ import androidx.compose.web.elements.Text ...@@ -8,23 +10,22 @@ import androidx.compose.web.elements.Text
import androidx.compose.web.renderComposable import androidx.compose.web.renderComposable
fun main() { fun main() {
val count = mutableStateOf(0) var count: Int by mutableStateOf(0)
renderComposable(rootElementId = "root") { renderComposable(rootElementId = "root") {
Div(style = { padding(25.px) }) { Div(style = { padding(25.px) }) {
Button(attrs = { Button(attrs = {
onClick { count.value = count.value - 1 } onClick { count -= 1 }
}) { }) {
Text("-") Text("-")
} }
Span(style = { padding(15.px) }) { Span(style = { padding(15.px) }) {
Text("${count.value}") Text("$count")
} }
Button(attrs = { Button(attrs = {
onClick { count.value = count.value + 1 } onClick { count += 1 }
}) { }) {
Text("+") Text("+")
} }
......
...@@ -115,6 +115,13 @@ fun main() { ...@@ -115,6 +115,13 @@ fun main() {
} }
} }
``` ```
In case you see an error:
`Type 'MutableState<TypeVariable(T)>' has no method 'getValue(Nothing?, KProperty<*>)'...` or
`Type 'MutableState<TypeVariable(T)>' 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 ## Running the project
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment