While using kotlin-multiplatform/js with react-redux, after the release, old way of setting-up the Redux Store Provider is deprecated (and may work only in kotlin-react-legacy lib). It was not easy to understand the new way of using it, because of lack of documentation and code examples. So here it is the working example)
The old way:
import react.dom.render
import react.router.dom.*
import react.redux.provider
import react.RBuilder
import redux.createStore
import redux.rEnhancer
import kotlinx.browser.document
fun main() {
val rootDiv = document.getElementById("root")!!
render(rootDiv) {
provider(store) { // this: {RBuilder}
app()
}
}
}
fun RBuilder.App() = { ... }
val store = createStore(::reducer, 0, rEnhancer())
fun reducer(state: Int = 0, action: Any): Int {
return when (action) {
is Increment -> state + 1
is Decrement -> state - 1
else -> state
}
}
class Increment : RAction
class Decrement : RAction
The new way, with Function Components and ChildrenBuilder: