Slide 1

Slide 1 text

KOTLIN WITH JAVASCRIPT & REACT: A REALITY

Slide 2

Slide 2 text

Hi, I’m Adora Software Engineer Creator, adorahack.com Co-organizer GDG Ajah, Unstack, Android Ngr Twitter: @theadoranwodo YouTube: adorahack

Slide 3

Slide 3 text

KOTLIN ?

Slide 4

Slide 4 text

Kotlin is a cross-platform, statically typed, general-purpose programming language with type inference.

Slide 5

Slide 5 text

WHY KOTLIN FOR JAVASCRIPT?

Slide 6

Slide 6 text

You’re not a fan of comparisons in Javascript '' == false 0 == false 0 === false null === undefined null == undefined null >= 0

Slide 7

Slide 7 text

Interoperability index.js function getToken(){ // do some stuff here // return a token string } Main.kt val TOKEN = js("getToken()") as String

Slide 8

Slide 8 text

Kotlin is modern & easy to learn.

Slide 9

Slide 9 text

Share code between platforms

Slide 10

Slide 10 text

KOTLIN & REACT

Slide 11

Slide 11 text

Create React Kotlin App. npm install -g create-react-kotlin-app Kotlin React Wrapper. npm i @jetbrains/kotlin-react

Slide 12

Slide 12 text

Lambdas are used in place of JSX when doing React with Kotlin

Slide 13

Slide 13 text

const Message = ({ message}) => { if (message ) { return (
Hey, {message}
); } return null } Functional Components - Message.js

Slide 14

Slide 14 text

fun RBuilder.alert(message: String = "") = if (message.isNotEmpty()) { div{ + “Hey, $message” } } else { empty } Functional Components - Message.kt

Slide 15

Slide 15 text

● RComponent ● RBuilder ● RState ● RProps ● RActions ● rEnhancer Some things to remember

Slide 16

Slide 16 text

interface WelcomeProps: RProps { var name: String } class Welcome: RComponent() { override fun RBuilder.render() { div { +"Hello, ${props.name}" } } } fun RBuilder.welcome(name: String = "John") = child(Welcome::class) { attrs.name = name } Class Components (Welcome.kt) Code snippet from https://github.com/JetBrains/kotlin-wrappers/tree/master/kotlin-react

Slide 17

Slide 17 text

Reusing Components Code snippet from https://github.com/JetBrains/kotlin-wrappers/tree/master/kotlin-react fun RBuilder.welcome(name: String = "John") = child(Welcome::class) { attrs.name = name }

Slide 18

Slide 18 text

OTHER KOTLIN WEB WRAPPERS

Slide 19

Slide 19 text

kotlin-css & kotlin-styled DSL for creating stylesheets in Kotlin. npm i @jetbrains/kotlin-css npm i @jetbrains/kotlin-css-js npm i @jetbrains/kotlin-styled

Slide 20

Slide 20 text

kotlin-mocha If you want to test, use this guy. npm i @jetbrains/kotlin-mocha

Slide 21

Slide 21 text

kotlin-react-dom Kotlin wrapper for the React DOM library. npm i @jetbrains/kotlin-react-dom

Slide 22

Slide 22 text

kotlin-react-redux Kotlin wrapper for the React Redux library. npm i @jetbrains/kotlin-react-redux

Slide 23

Slide 23 text

kotlin-react-router-dom Kotlin wrapper for the React Router DOM library. npm i @jetbrains/kotlin-react-router-dom

Slide 24

Slide 24 text

kotlin-redux Kotlin wrapper for the Redux library. npm i @jetbrains/kotlin-redux

Slide 25

Slide 25 text

● Introduction to Kotlin ● Why Kotlin for JavaScript ● Kotlin in React ● Existing Kotlin JS wrappers Summary

Slide 26

Slide 26 text

● https://kotlinlang.org/docs/reference/js-overview.html ● https://github.com/JetBrains/kotlin-wrappers ● https://github.com/JetBrains/create-react-kotlin-app ● https://adorahack.com Helpful resources

Slide 27

Slide 27 text

Build for the web however you like!

Slide 28

Slide 28 text

THANKS! Website: adoranwodo.com Blog: adorahack.com Twitter: @adoranwodo