touchlab / KaMPKit

KaMP Kit by Touchlab. A collection of code & tools designed to get your mobile team started quickly w/Kotlin Multiplatform
https://touchlab.co/
Apache License 2.0
2.17k stars 196 forks source link

JS/React model #269

Closed mikedawson closed 1 year ago

mikedawson commented 1 year ago

Hi,

This example has served as an excellent starting point! I am beginning to have some success using Kotlin/JS with React as part of KMP project where ViewModels are shared with Android.

I made a few React hooks so we get something that looks like this:

val DummyScreen = FC<Props>() {
    val di = useContext(DIContext)

    val viewModel = useViewModel { DummyViewModel() }

    val dummyUiState: DummyUiState by viewModel.uiState.collectAsState(DummyUiState())

    val person: Person? by dummyUiState.personState.collectAsState(null)

    Typography {
        + "Hello ${person?.firstNames}"
    }
}

I know Android and iOS are the focus for Kotlin Multiplatform at the moment, but the new wrappers are making Kotlin/JS usable. I think having a solid demo here where many people are looking would be an asset.

I'd be happy to work on a pull request for that.

russhwolf commented 1 year ago

We appreciate the enthusiasm, but at the moment we're not looking to maintain a javascript target in KaMPKit. Glad you've found it helpful, though!