Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

v0.2.0

Choose a tag to compare

@bnorm bnorm released this 05 Sep 21:43
· 58 commits to main since this release

New Features

  • Support React component keys via @RKey annotation
plugins {
  kotlin("js") version "1.4.0"
  id("com.bnorm.react.kotlin-react-function") version "0.2.0"
}

dependencies {
  implementation("com.bnorm.react:kotlin-react-function:0.2.0")
}

Component Key

To set the key of a React functional component, use the @RKey annotation on a
single parameter to a @RFunction annotated function.

@RFunction
fun RBuilder.ListItem(@RKey item: Item) {
  ...
}

This uses the toString() value of the annotated parameter as the key for the
component. If the value of the key needs to be controlled more explicitly, mark
an unused parameter as the key.

@RFunction
fun RBuilder.Component(... other parameters ..., @RKey key: String) {
  // `key` doesn't need to be used to be set as the key of the component
}

If the @RKey annotated parameter is null, then the string "null" will be
set as the component key. It is also possible to use default parameters to
derive the key from another parameter.