Ilya P
08/22/2023, 12:14 PMjs()
and it's confusingly doesn't work. Details in 🧵Ilya P
08/22/2023, 12:14 PMval App = FC<Props> { ... }
Ilya P
08/22/2023, 12:15 PMval browserRouter = createBrowserRouter(arrayOf(js("""{ path: "/", element: App.create() }""")))
Ilya P
08/22/2023, 12:15 PMApp
val is renamed to App_0
Ilya P
08/22/2023, 12:16 PMApp
in js code, but how then do I refer to the variables from the js block?Ilya P
08/22/2023, 12:18 PMAbraham
08/22/2023, 12:24 PMval App = FC<Props> { ... }
defines a KT object, but element: App.create()
expects a JS object but App is referred by App_0 in the JS generated codeIlya P
08/22/2023, 12:25 PMIlya P
08/22/2023, 12:25 PMfun browserRouter(app: FC<*>): Router {
js("console.log(app)")
return createBrowserRouter(arrayOf(js("""{ path: "/", element: React.createElement(app) }""")))
}
Ilya P
08/22/2023, 12:25 PMIlya P
08/22/2023, 12:25 PMIlya P
08/22/2023, 12:26 PMIlya P
08/22/2023, 12:26 PMIlya P
08/22/2023, 12:27 PMArtem Kobzar
08/22/2023, 12:27 PMexternal interface BrowserRouterOpts {
val path: String
val element: ReactElement // <- not sure about the type
}
fun browserRouter(app: FC<*>): Router {
return createBrowserRouter(object : BrowserRouterOpts {
override val path = "/"
override val element = React.createElement(app)
})
}
Ilya P
08/22/2023, 12:27 PMIlya P
08/22/2023, 12:28 PMIlya P
08/22/2023, 12:28 PMIlya P
08/22/2023, 12:28 PMIlya P
08/22/2023, 12:29 PMRouteObject
and it's unusableEdoardo Luppi
08/22/2023, 1:11 PMWhich is a sealed external interfaceMaybe @turansky knows why a lot of types are sealed, that's also something I was wondering (https://github.com/JetBrains/kotlin-wrappers/blob/d9346f3a825e53efbc64465faedb0efc[…]n-react-router/src/jsMain/generated/react/router/RouteObject.kt)
turansky
08/22/2023, 1:24 PMRouteObject
creation example is hereRob Murdock
08/22/2023, 1:25 PMjso
exampleturansky
08/22/2023, 1:29 PMjs()
call.
We generate declarations to provide strict interoperability.
If you see only hacky way how to solve your problem - you can write in this channel - we will provide strict solutions 🙂turansky
08/22/2023, 1:31 PM// type parameter is redundant
val App = FC<Props> { ... }
// expected call
val App = FC { ... }
Ilya P
08/22/2023, 1:31 PMRob Murdock
08/22/2023, 1:31 PMjso
function is because its only included in one of the wrapper libsRob Murdock
08/22/2023, 1:31 PMIlya P
08/22/2023, 1:32 PMIlya P
08/22/2023, 1:33 PMturansky
08/22/2023, 1:33 PMkotlin-extentions
is deprecated and doesn’t contain jso
.Rob Murdock
08/22/2023, 1:33 PMRob Murdock
08/22/2023, 1:33 PMIlya P
08/22/2023, 1:33 PMIlya P
08/22/2023, 1:34 PMturansky
08/22/2023, 1:35 PMjso
is available in kotlin-wrappers:kotlin-js
.
You will receive it transitively with any other wrappers dependency.Rob Murdock
08/22/2023, 1:36 PMinline fun <T : Any> jso(): T =
js("({})")
inline fun <T : Any> jso(
block: @JsoDsl T.() -> Unit,
): T =
jso<T>().apply(block)
Basically it works the same way the react props builders work - it lets you typesafely assign the vars given the appropriate TRob Murdock
08/22/2023, 1:37 PMIlya P
08/22/2023, 1:37 PMIlya P
08/22/2023, 1:38 PMRob Murdock
08/22/2023, 1:39 PMRob Murdock
08/22/2023, 1:40 PMIlya P
08/22/2023, 1:56 PMfun main() {
val container = document.getElementById("root") ?: error("Root element not found")
createRoot(container).render(RouterProvider.create { router = browserRouter })
}
val browserRouter = createBrowserRouter(arrayOf(
jso {
path = "/"
Component = App
ErrorBoundary = Err
}
))
It says "Matched leaf route at location "/" does not have an element or Component." on loading and obv doesn't render anything.Rob Murdock
08/22/2023, 1:59 PMIlya P
08/22/2023, 2:00 PMIlya P
08/22/2023, 2:00 PMIlya P
08/22/2023, 2:01 PMIlya P
08/22/2023, 2:01 PMRob Murdock
08/22/2023, 2:02 PMIlya P
08/22/2023, 2:03 PMRob Murdock
08/22/2023, 2:05 PMIlya P
08/22/2023, 2:05 PMelement = App.create()
?Rob Murdock
08/22/2023, 2:06 PMcreate
function either with a closure for prop-passing or without it works wellRob Murdock
08/22/2023, 2:06 PM<App/>
Ilya P
08/22/2023, 2:07 PMIlya P
08/22/2023, 2:07 PMIlya P
08/22/2023, 2:07 PMRob Murdock
08/22/2023, 2:07 PMIlya P
08/22/2023, 2:09 PMval browserRouter = createBrowserRouter(arrayOf(
jso {
path = "/"
element = Test.create()
}
))
val Test = FC {
div { h1 { +"Test" } }
}
Ilya P
08/22/2023, 2:09 PMIlya P
08/22/2023, 2:10 PMError: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Rob Murdock
08/22/2023, 2:10 PMIlya P
08/22/2023, 2:11 PMIlya P
08/22/2023, 2:11 PMIlya P
08/22/2023, 2:11 PMIlya P
08/22/2023, 2:11 PMRob Murdock
08/22/2023, 2:12 PMIlya P
08/22/2023, 2:12 PMIlya P
08/22/2023, 2:13 PMRob Murdock
08/22/2023, 2:13 PMturansky
08/22/2023, 3:04 PMComponent
property, it works fine.
Especially when you use one component for different pages.turansky
08/22/2023, 3:05 PMThis failsWhich Kotlin version do you use?
turansky
08/22/2023, 3:06 PMuseConstant
hook can be used from kotlin-react-use
Ilya P
08/23/2023, 7:11 AMIlya P
08/23/2023, 7:12 AMturansky
08/23/2023, 7:12 AMIlya P
08/23/2023, 7:12 AMIlya P
08/23/2023, 7:13 AMIlya P
08/23/2023, 7:13 AMturansky
08/23/2023, 7:36 AM