SlideShare a Scribd company logo
Kotlin loves React
Davide Cerbo
Software Architect @ E.m.m. Informatica
Milan | November 29 - 30, 2018
Davide Cerbo
15+ years as developer
DevDay Community Leader
@davide_cerbo
https://medium.com/@davidecerbo
Davide Cerbo - Kotlin loves React - Codemotion Milan 2018
Kotlin is a statically-typed programming
language that runs on the Java Virtual Machine
and also can be compiled to JavaScript source
code or uses the LLVM compiler infrastructure.
https://dzone.com/articles/why-learn-kotlin-infographic
Predicatability not performance:https://www.youtube.com/watch?v=ExkNNsDn6Vg
Since 2010 (2012): KOTLIN!
100% interoperable
with Java ☕
~40% less lines of
code than Java 🍀
Easy to learn, if you
know Java 📚
JetBrains 🚀
It’s safe 👮
Apache 2 ⛺
PerformancePredictability 👍
May 2018
ThoughtWorks suggests to adopt Kotlin in its
Technlogy Radar
https://www.thoughtworks.com/radar/languages-and-frameworks/kotlin
May
2017
Nov
2017
May
2018
TrialAsses Adopt
My first API with Ktor
fun main(args: Array<String>) {
val server = embeddedServer(Netty, 8080) {
install(ContentNegotiation) {
jackson { enable(SerializationFeature.INDENT_OUTPUT) // Pretty Prints the JSON }
}
routing {
get("/greetings") {
call.respond(Greetings().sayGreetings())
}
}
}
server.start(wait = true)
}
Greetings
actual class Greetings {
actual fun sayGreetings(): String {
return "Hello from JVM world!!!"
}
}
but...
KotlinJS can!
● No longer experimental since 1.1.0
● Can run anywhere where JS runs
● Can interoperate with JS
● Can reuse code
● Can use the same Kotlin/JVM IDE
wait, React?
React
A JavaScript library for
building user interfaces.
The V in MVC
Components, not templates.
Re-render, don’t mutate.
Virtual DOM is simple and fast
setState({a:1})
Kotlin React Wrapper
https://github.com/JetBrains/kotlin-wra
ppers/blob/master/kotlin-react/src/mai
n/kotlin/react/React.kt
Kotlin (experimental) Multiplatform
https://github.com/gbaldeck/react-js-jv
m-kotlin-multiplatform
Demo!!!
https://github.com/jest
y/kotlin-loves-react
Main
import app.*
import kotlinext.js.*
import react.dom.*
import kotlin.browser.*
fun main(args: Array<String>) {
requireAll(require.context("src", true, js("/.css$/")))
render(document.getElementById("root")) {
app()
}
}
Components
class Welcome :
RComponent<RProps,
RState>() {
State & Props
interface WelcomeProps : RProps {
var name: String
}
interface WelcomeState : RState {
var color: String
}
Components with state & props
class Welcome :
RComponent<WelcomeProps,
WelcomeState>() {
Render
override fun RBuilder.render() {
div {
+"Hello, ${props.name} - ${state.color}"
button {
+"Click me ${props.name}"
attrs {
onClickFunction = {
setState { color = "red" }
} } } }
}
https://kotlinlang.org/docs/reference/type-safe-builders.html
Weird! This pass this
Style
import kotlinext.js.js
//...
div {
attr.title = “Hello”
//Not typesafe, js body function must be a constant
attr.style= js { color: “red” }
//no constant issue
jsStyle { color = “red” }
}
//...
Routing
hashRouter {
switch {
route("/", IndexComponent::class, exact = true)
route("/about", AboutComponent::class, exact = true)
}
}
//Link
routeLink("/about") { +"About" }
setState {a =1}
JS
interoperation
fun dynamicExample() {
val a: dynamic = js("{ foo: function () { console.log(Hi!')} }")
a.foo()
a.bar() //Uncaught TypeError: a.bar is not a function
}
fun externalExample() {
val e = E()
e.foo()
//e.bar() //Compile time error!!!
}
external class E {
fun foo()
}
//helloworld.js
var E = function(){
this.foo = function () {
console.log('Hello world! (external)')
} }
fun actualExpectExample() {
val ea = EA()
ea.foo()
}
expect class EA {
fun foo()
}
//in a JS project
actual class EA {
fun foo() { println("Hello from JS!") }
}
//in a JVM project
actual class EA {
fun foo() { println("Hello from JVM!") }
}
if (typeof kotlin === 'undefined') {
throw new Error("Error loading module 'codemotion'. Its dependency 'kotlin'
was not found. Please, check whether 'kotlin' is loaded prior to 'github'.");
}
var github = function (_, Kotlin) {
'use strict';
var println = Kotlin.kotlin.io.println_s8jyv4$;
var Kind_CLASS = Kotlin.Kind.CLASS;
function dynamicExample() {
var a = {foo: function () {
console.log('Hello world! (dynamic)');
}};
a.foo();
}
function externalExample() {
var e = new E();
e.foo();
(Auto)references
● https://github.com/jesty/kotlin-fossavotabona
● https://github.com/jesty/reactiveredis
At the end...
Dynamic Vs. Static typed
Static: Types checked before run-time
Dynamic: Types checked on the fly, during execution
Typescript Vs. KotlinJs
TypeScript is a
superset of
Javascript.
Kotlin aims to be
full-stack for creating
apps.
https://www.slant.co/versus/378/1543/~typescript_vs_kotlin
https://discuss.kotlinlang.org/t/feedback-on-our-migration-from-typescript-to-kotlin/2578
Davide Cerbo - Kotlin loves React - Codemotion Milan 2018
Davide Cerbo - Kotlin loves React - Codemotion Milan 2018
but...
...suspance...
Webassembly?
Davide Cerbo - Kotlin loves React - Codemotion Milan 2018
The end!https://twitter.com/davide_cerbo
let's talk?
let’s talk?
http://devday.it

More Related Content

PPTX
Intro to kotlin
PDF
Kotlin for Android Development
PPTX
Coding in kotlin
PPSX
Kotlin Language powerpoint show file
PDF
Introduction to Kotlin JVM language
PDF
A quick and fast intro to Kotlin
PDF
15 Minutes Null
PDF
Android 101 - Kotlin ( Future of Android Development)
Intro to kotlin
Kotlin for Android Development
Coding in kotlin
Kotlin Language powerpoint show file
Introduction to Kotlin JVM language
A quick and fast intro to Kotlin
15 Minutes Null
Android 101 - Kotlin ( Future of Android Development)

What's hot (20)

PPTX
JS Fest 2018. Виталий Ратушный. ES X
PPTX
Code for kombol - Objects and Functions in JS and NodeJS
PPTX
Why I don’t want to develop iOS apps in Objective C
PDF
Elixir + GraphQL = Absinthe 2019.04.10
PPTX
JS Fest 2018. Douglas Crockford. The Better Parts
PDF
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...
PDF
freeCodeCampTokyoMeetup 17
ODP
JavaScript Object Oriented Programming Cheat Sheet
PPTX
JavaScript (without DOM)
PDF
Coffee script
PDF
AngularJS
PPTX
AST for JavaScript developers
PDF
Introduction to Object Oriented Javascript
PPTX
Flexible Types in Kotlin - JVMLS 2015
PPTX
Declarative JavaScript concepts and implemetation
PDF
Back to the future: Isomorphic javascript applications
PPTX
JavaScript operators
PDF
Swift language - A fast overview of some features
ODP
Crossing Office Applications
ODP
JavaScript global object, execution contexts & closures
JS Fest 2018. Виталий Ратушный. ES X
Code for kombol - Objects and Functions in JS and NodeJS
Why I don’t want to develop iOS apps in Objective C
Elixir + GraphQL = Absinthe 2019.04.10
JS Fest 2018. Douglas Crockford. The Better Parts
JS Fest 2018. Никита Галкин. Микросервисная архитектура с переиспользуемыми к...
freeCodeCampTokyoMeetup 17
JavaScript Object Oriented Programming Cheat Sheet
JavaScript (without DOM)
Coffee script
AngularJS
AST for JavaScript developers
Introduction to Object Oriented Javascript
Flexible Types in Kotlin - JVMLS 2015
Declarative JavaScript concepts and implemetation
Back to the future: Isomorphic javascript applications
JavaScript operators
Swift language - A fast overview of some features
Crossing Office Applications
JavaScript global object, execution contexts & closures
Ad

Similar to Davide Cerbo - Kotlin loves React - Codemotion Milan 2018 (20)

PPTX
A TypeScript Fans KotlinJS Adventures
PPTX
TypeScript Vs. KotlinJS
PDF
Rapid Web API development with Kotlin and Ktor
PDF
Exploring Kotlin
PDF
Introduction to Kotlin - Android KTX
PDF
Intro to Kotlin
PDF
9054799 dzone-refcard267-kotlin
PDF
Little Helpers for Android Development with Kotlin
PDF
Kotlin: Why Do You Care?
PDF
Coding for Android on steroids with Kotlin
PDF
Why Kotlin is your next language?
PDF
JavaOne 2016 - Kotlin: The Language of The Future For JVM?
PDF
Kotlin: A pragmatic language by JetBrains
PDF
Kotlin, smarter development for the jvm
PDF
A short introduction to the Kotlin language for Java developers
PPTX
Introduction to Kotlin Language and its application to Android platform
PDF
JDD 2017: Kotlin for Java developers (Tomasz Kleszczyński)
PPTX
Google Cloud Functions: try { Kotlin } instead of JavaScript
PPTX
K is for Kotlin
PDF
Android 101 - Building a simple app with Kotlin in 90 minutes
A TypeScript Fans KotlinJS Adventures
TypeScript Vs. KotlinJS
Rapid Web API development with Kotlin and Ktor
Exploring Kotlin
Introduction to Kotlin - Android KTX
Intro to Kotlin
9054799 dzone-refcard267-kotlin
Little Helpers for Android Development with Kotlin
Kotlin: Why Do You Care?
Coding for Android on steroids with Kotlin
Why Kotlin is your next language?
JavaOne 2016 - Kotlin: The Language of The Future For JVM?
Kotlin: A pragmatic language by JetBrains
Kotlin, smarter development for the jvm
A short introduction to the Kotlin language for Java developers
Introduction to Kotlin Language and its application to Android platform
JDD 2017: Kotlin for Java developers (Tomasz Kleszczyński)
Google Cloud Functions: try { Kotlin } instead of JavaScript
K is for Kotlin
Android 101 - Building a simple app with Kotlin in 90 minutes
Ad

More from Codemotion (20)

PDF
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
PDF
Pompili - From hero to_zero: The FatalNoise neverending story
PPTX
Pastore - Commodore 65 - La storia
PPTX
Pennisi - Essere Richard Altwasser
PPTX
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
PPTX
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
PPTX
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
PPTX
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
PDF
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
PDF
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
PDF
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
PDF
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
PDF
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
PDF
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
PPTX
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
PPTX
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
PDF
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
PDF
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
PDF
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
PDF
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Pompili - From hero to_zero: The FatalNoise neverending story
Pastore - Commodore 65 - La storia
Pennisi - Essere Richard Altwasser
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Electronic commerce courselecture one. Pdf
PPTX
Cloud computing and distributed systems.
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Approach and Philosophy of On baking technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
A Presentation on Artificial Intelligence
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Encapsulation theory and applications.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
cuic standard and advanced reporting.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
A comparative analysis of optical character recognition models for extracting...
Electronic commerce courselecture one. Pdf
Cloud computing and distributed systems.
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Approach and Philosophy of On baking technology
Programs and apps: productivity, graphics, security and other tools
A Presentation on Artificial Intelligence
Digital-Transformation-Roadmap-for-Companies.pptx
Unlocking AI with Model Context Protocol (MCP)
MYSQL Presentation for SQL database connectivity
Chapter 3 Spatial Domain Image Processing.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Encapsulation theory and applications.pdf
The AUB Centre for AI in Media Proposal.docx
cuic standard and advanced reporting.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm

Davide Cerbo - Kotlin loves React - Codemotion Milan 2018