Jonathan Lennox
07/10/2024, 9:42 PMJonathan Lennox
07/10/2024, 9:42 PMimport kotlinx.css.span
import react.RBuilder
import react.RComponent
import react.RProps
import react.RState
import react.dom.div
import react.dom.span
import react.router.dom.hashRouter
import react.router.dom.route
import react.router.dom.routeLink
import react.router.dom.switch
class App : RComponent<RProps, RState>() {
override fun RBuilder.render() {
hashRouter {
switch {
route("/", exact = true) {
div {
routeLink("/dump") {
+"Dump viewer"
}
span {
+" | "
}
routeLink("/live") {
+"Live dashboard"
}
}
}
route("/dump", Dump::class, exact = true)
route("/live", LiveDashboard::class, exact = true)
}
}
}
}
Jonathan Lennox
07/10/2024, 9:43 PMturansky
07/11/2024, 7:23 AMturansky
07/11/2024, 7:24 AMI'm pretty sure I need kotlin-react-legacyYou can use it as intermediate step
turansky
07/11/2024, 7:24 AMkotlin-react
at start is fineJonathan Lennox
07/11/2024, 4:49 PMcreateHashRouter
work in override fun RBuilder.render()
? All the existing code I'm modifying is based on that APIJonathan Lennox
07/11/2024, 4:52 PMoverride fun RBuilder.render() {
console.log("graph selection rendering")
child(Selector::class) {
attrs {
onSelectedKeysChange = this@ChartSelection::selectedKeysChanged
allKeys = props.allKeys
}
ref {
selector = it as? Selector
}
}
child(Chart::class) {
attrs {
title = props.title
enableZoom = haveStoredData()
graphType = props.graphType ?: "line"
startZoomSeconds = props.startZoomSeconds
}
ref {
chart = it as? Chart
}
}
}
And I get
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public open fun <T> Consumer<TypeVariable(T)>.invoke(handler: RBuilder.(TypeVariable(T)) -> Unit): Unit defined in react.RElementBuilder
public open fun <P : Props> ElementType<TypeVariable(P)>.invoke(): Unit defined in react.RElementBuilder
public open fun <P : Props> ElementType<TypeVariable(P)>.invoke(handler: RHandler<TypeVariable(P)> /* = RElementBuilder<TypeVariable(P)>.() -> Unit */): Unit defined in react.RElementBuilder
public open fun <T> Provider<TypeVariable(T)>.invoke(value: TypeVariable(T), handler: RHandler<ProviderProps<TypeVariable(T)>> /* = RElementBuilder<ProviderProps<TypeVariable(T)>>.() -> Unit */): Unit defined in react.RElementBuilder
What should I be doing instead?Jonathan Lennox
07/11/2024, 9:11 PMref = useRefCallback<Chart> {
chart = it
}
but I still haven't figured out the hashRouter.Jonathan Lennox
07/11/2024, 9:14 PMimport react.RBuilder
import react.RComponent
import react.PropsWithChildren
import react.State
import react.router.*
import react.router.dom.createHashRouter
class App : RComponent<PropsWithChildren, State>() {
private val hashRouter = createHashRouter(
routes = arrayOf(
)
)
override fun RBuilder.render() {
RouterProvider {
router = hashRouter
}
}
}
Gives me Unresolved reference: router
for the parameter to RouterProvider, which I don't understand. What am I doing wrong?turansky
07/12/2024, 9:44 AMRBuilder
requires redundant attrs
block.turansky
07/12/2024, 9:45 AMoverride fun RBuilder.render() {
RouterProvider {
attrs {
router = hashRouter
}
}
}
Jonathan Lennox
07/15/2024, 6:58 PMUncaught 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:
at runtime.Jonathan Lennox
07/15/2024, 7:43 PMref = RefCallback<Chart>
, not ref = useRefCallback<Chart>
.turansky
07/15/2024, 8:09 PMuseRefCallback
required if need memoization for callback.
Otherwise you will force redundant rerenderings.turansky
07/15/2024, 8:10 PMuseRefCallback
- hook and should be called on top level of functional component