Filippo Orru
12/02/2019, 8:16 AMuseState(0)
Hook doesn't work!
It throws the following Error:
Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons (...)
and then lists the reasons. Why is that? My Code is the following:Filippo Orru
12/02/2019, 8:17 AMpackage <http://jsonApp.app|jsonApp.app>
import kotlinx.html.js.onClickFunction
import react.*
import react.dom.*
class App : RComponent<RProps, RState>() {
override fun RBuilder.render() {
div {
+"jsonapp"
counter()
}
}
}
fun RBuilder.jsonApp() = child(App::class) {}
fun RBuilder.counter() {
div("count") {
val countState: Pair<Int, (Int) -> Unit> = useState(0)
span { +"You be walking a lot. ${countState.first} steps already" }
button {
attrs.onClickFunction = { countState.second(countState.first + 1) }
+"Step"
}
}
}
Filippo Orru
12/02/2019, 9:03 AMfun counter() = functionalComponent<RProps>() {...}
and then call it with child(counter())
Darren Bell
01/13/2020, 10:18 AMprops
from within the functionalComponent
I have been having the same issue as mentioned here https://github.com/JetBrains/kotlin-wrappers/issues/131 and was wondering if there is a work aroundFilippo Orru
01/13/2020, 12:14 PMfun test = functionalComponent<>() = ...
instead of RBuilder.test() = ...
directly. I didn't need to access the props so I didn't run into your problem.Darren Bell
01/13/2020, 12:26 PMFilippo Orru
01/13/2020, 1:47 PMDarren Bell
01/13/2020, 4:45 PM