I’m not happy with `kotlin-react` and `kotlinx-htm...
# javascript
m
I’m not happy with
kotlin-react
and
kotlinx-html
, so I’ve started my own React wrapper. • Similar to kotlin-react. • Nicer and consistent API. Easier to use. • Not multiplatform. Optimized for Kotlin/JS instead. • No dependencies beside React [Router]. • Lower size and performance overhead. • More type safety, esp. around hooks. • Props allow
class
instead of just
external interface
. • Highly experimental. IR compiler only. Relies on unofficial compiler behavior. Anyone wants to join the project? 😄 https://github.com/fluidsonic/fluid-react
👏 7
K 5
How the CSS library currently works:
Component example from my project
a
While I am also not happy with
kotlin-react
I have no problems with
kotlin-styled
at all, its syntax was so concise. I considering joining you i this one
b
I'd love to help. Do you have some issues written up?
a
looks like there is none at the moment
I don't know performance wise but,
Copy code
val PriceCard : RComponent<PriceCardProps> by react.component { props->
  // . . . 
}
looks so much better than
Copy code
val Component:RComponent<PriceCardProps> = react.component("PriceCard"){props->
  // . . .
}
2
m
While I am also not happy with kotlin-react I have no problems with kotlin-styled at all, its syntax was so concise.
I  considering joining you i this one
Interesting. I was particularly unhappy with
styled
which is why I’ve written my own CSS library.
Copy code
val PriceCard : RComponent<PriceCardProps> by react.component { props->
  // . . . 
}
You can. I don’t use that in my project for two reasons: a) My components are private. I expose wrapper functions like this:
b) The String is used by React Debugging Tools to show the name of each component in the tree. Performance-wise there’s no difference. The String isn’t included in production builds.
b
Wouldn't it be better to copy what kotlinx.html does and generate all html tags from schema?
m
No.
kotlinx-html
targets pure HTML. There are several issues open for
kotlin-react
and
kotlinx-html
due to incompatibility with React. React expects different casing for properties (DOM camel case instead of lowercase), different types (DOM types e.g. booleans, integers, etc.) and there are some React specifics (e.g.
style
being an object). Given enough time it may be possible to write a generator, but I don’t think it’s worth it.
c
do you also plan a wrapper for react-testing-library?
m
I’ve never used that library. Nothing is planned for testing so far. I’ve spent a lot of time on react and CSS libs so it’s time to finish the actual project built on top of it 😅
a
In your part B, using delegates, you can assign the name of the component to be the variable name
I think what @Big Chungus suggests is, generating the html tags from a schema. Not copying exact implementation from
kotlinx-html
m
Yes, delegation could indeed make the name available. I completely read over the
by
in the suggestion 😄 But delegation adds quite some overhead. Also the name cannot be removed from production builds then – they’re only supposed to be used in debug builds.
But I can do some experiments if I find way to optimize that.
external
&
inline
are like all-purpose optimization tools 🙂
Alright, I think I found a way to optimize it. But every library user would have to set up optimization like this:
a
elaborate please
m
The compiler generates weird stuff like the following, which is also included in production builds. Using the Terser optimization settings from above the optimizer can then remove that garbage from production builds.
Alright, I’ve added component naming by delegation 🙂 https://github.com/fluidsonic/fluid-react/blob/c5efcc205e76560527cd98ff0ec4f243f264c470/modules/playground/sources/js/EmojiContainer.kt#L5 Thanks for the suggestion and sorry for the misunderstanding earlier. The resulting code will be slightly less performance and larger in size. That can be compensated by improving settings of the Webpack minification. I’ll add some advice on that later on.
b
Just recently I also started writing my own wrapper. I wanted to make use of the
DslMarkers
which is almost impossible with the current split between builder and components. Hence I came up with this:
Copy code
rootDiv.reakt {
    +TestComponent(prop1 = "Test") {
        +TestComponent(prop1 = "Test3") {
            +Div("test4") {
                attrs {
                    id = "test"
                }
            }
        }
        +"Lol"
        +TestComponent()
    }
}

class TestComponent(
    prop1: String = "lol",
    handler: ReaktBase.ReaktHandler<TestComponent> = ReaktBase.ReaktHandler { }
) : Component<TestComponent, TestComponent.Props>(handler) {
  ...
}
It’s neither working yet, nor is it commited somewhere. And I am not sure if I want to follow this path. Seeing your project gives me hope though, that we will have a nice to use dsl for react in kotlin.
b
DSL markers are great!