我想创建一个包含“html”代码段的方法,但我收到以下错误.
import react.dom.a
import react.dom.button
import react.dom.div
import react.dom.nav
import react.dom.span
import kotlinx.html.ButtonType
import react.RBuilder
import react.RComponent
import react.RProps
import react.RState
class App : RComponent<RProps, RState>() {
override fun RBuilder.render() {
div("container fill") {
}
div {
content()
}
}
fun content() {
return div() { } // the error below is for this line
}
}
error: unresolved reference. None of the following candidates is
applicable because of receiver type mismatch: public inline fun
RBuilder.div(classes: String? = …, block: RDOMBuilder.() ->
Unit): ReactElement defined in react.dom
return div() {
有任何想法吗?
最佳答案 你应该添加接收器,并可能像这样摆脱回报:
class App : RComponent<RProps, RState>() {
override fun RBuilder.render() {
div("container fill") {
}
div {
content()
}
}
fun RBuilder.content() {
div() { }
}
}