https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
react
  • p

    Paul SOUTEYRAT

    07/07/2021, 2:40 PM
    Hi, I just updated
    kotlin-react
    and I saw that hooks' usage has changed and older usage has been deprecated. Overall this change seems good because it brings consistency (using vararg). However, I have a slight issue because I wish to use
    useEffect
    with the new usage, but I can't when passing a single dependency which is either a list or a dynamic variable. For instance:
    useEffect(myDynamicVariable) {
         //EffectBuilder
    }
    With this code IntelliJ warns about deprecation, and, when running,
    Uncaught TypeError: collection.iterator is not a function
    is thrown because
    myDynamicValue
    is interpreted as a list. The same issue occurs when passing a single list as the only dependency (even though it does not throw a TypeError). Any idea on how I can fix this issue ?
    t
    • 2
    • 11
  • l

    Lazard

    07/07/2021, 7:30 PM
    Hi everyone, I'm not very skilled with Kotlin React for now but I was wondering how does the support for npm packages works right now ? Let's say I want to use a pretty complex module like Mantine (core and/or hooks), how easy it is to use it with Kotlin ? I'd guess merely declaring the package won't help much I'd still need "signatures" for all the functions. Do I need to declare manually every single components/hooks or is there a way to save time ?
    t
    • 2
    • 10
  • b

    bsimmons

    07/12/2021, 2:39 PM
    Hey all, is there an easy way to style router links? Currently, I'm doing something jenky like this.
    routeLink("/contact") {
        ref {
            it?.style?.textDecoration = "none"
            it?.style?.color = "inherit"
        }
        +"Jane Rogers"
    }
    ✅ 2
    t
    • 2
    • 2
  • p

    Paul SOUTEYRAT

    07/25/2021, 8:01 PM
    Hi, I just saw that the ref usage has changed with 0a1fa23. I don't understand how I am supposed to use Callback Refs now. Does someone has a simple example please ?
    t
    • 2
    • 3
  • b

    bsimmons

    07/26/2021, 1:16 PM
    Hey all, I'm trying to use this react package from NPM following the setup from this tutorial. But I keep getting an "Invalid hook call" warning when I run it. I can only image it's because the package is using a FunctionComponent rather than a regular class. Any ideas?
    t
    • 2
    • 5
  • c

    cfnz

    07/29/2021, 10:17 PM
    https://github.com/JetBrains/kotlin-wrappers/pull/564 looks like it might break a few things which is fine if there is good reason. Is there a place where such changes are described? For example, is this to make things more "React like"? I could not find an issue discussing it or anything describing the why.
    t
    • 2
    • 8
  • b

    bsimmons

    08/04/2021, 12:09 PM
    Is it possible to add a function as the children property of a component? This seems to be a common react JS thing that I can't figure out in Kotlin. For example, how would one implement this lib? react-virtualized-auto-sizer
    t
    s
    • 3
    • 39
  • j

    joney

    08/04/2021, 8:36 PM
    Using
    kotlin-wrappers-bom:0.0.1-pre.213-kotlin-1.5.10
    works just fine. For newer versions
    compileKotlinJs
    fails with
    Unresolved reference: react
    even though the IDE does not complain and the source files get resolved. Any hints? I tried clean and invalidate caches/restart.... (:kotlinnew:
    1.5.21
    and :gradle:
    7.1.1
    )
    ✔️ 1
    t
    • 2
    • 12
  • g

    GUIGAL Allan

    08/09/2021, 11:50 PM
    It looks like the useEffectOnce doesn’t have the behavior I’m expecting. Either I misunderstood it or it’s not working properly : Whenever I update a component above the one using this useEffectOnce component AND there is a dom update to be made => Then the useEffectOnce is triggered again. Is it the expected behavior ? I’ve instead implemented my own hook for such a purpose with useRef, any opinion ? Example in the answers :
    t
    s
    p
    • 4
    • 19
  • c

    cfnz

    08/12/2021, 10:52 PM
    Now that the wrapper child functions don't return a ReactElement, what is the best way to get and assign a ReactElement, for example, given this js:
    renderOption={(option) => (
            <React.Fragment>
              <span>
                {option.label}
              </span>
            </React.Fragment>
          )}
    In my Kotlin code, it used to be like this:
    renderOption = { option, _ ->
        Fragment {
            span {
                +option.label
            }
        }
    }
    What is the recommended way of doing this now?
    t
    • 2
    • 11
  • m

    Mark

    08/20/2021, 4:59 PM
    Hello, I decided to give Kotlin React a try, in IJ I made a new Kotlin React project, without changing anything I ran the default
    BrowserDevelopmentRun in continuous mode
    task, it ran fine, however the localhost did not pop in my browser, going to
    localhost:8080
    doesn't seem to have anything
    This site can't be reached
    , same for
    :3000
    . In the run window in IJ there is a warning:
    [webpack-cli] Invalid configuration object. Object has been initialized using a configuration object that does not match the API schema.
     - configuration has an unknown property '_assetEmittingWrittenFiles'. These properties are valid:
       object { bonjour?, client?, compress?, dev?, firewall?, headers?, historyApiFallback?, host?, hot?, http2?, https?, liveReload?, onAfterSetupMiddleware?, onBeforeSetupMiddleware?, onListening?, open?, port?, proxy?, public?, setupExitSignals?, static?, transportMode?, watchFiles? }
    Happens both with IR and Legacy.
    r
    • 2
    • 2
  • a

    andylamax

    09/04/2021, 11:20 AM
    Hello, I like very much the late refactor of
    kotlin-react.
    A lot of things are now very consistent. Follow question though. I see that we have
    interface RBuilder {
        // . . . 
        fun <P : Props> child(
            klazz: KClass<out Component<P, *>>,
            handler: RHandler<P>,
        )
        // . . .
    }
    Question is, why don't we have
    interface RBuilder {
        // . . . 
        fun <P : Props> child(
            klazz: KClass<out Component<P, *>>,
            props: P,
            handler: RHandler<P>,
        )
        // . . .
    }
    So that I may
    child(Hellow::class,jsObject{
      param1 = 1
      param2 = 2
      param3 = "three"
      // . . . 
    })
    instead of
    child(Hellow::class) {
     attrs {
      param1 = 1
      param2 = 2
      param3 = "three"    
     }
    }
    t
    • 2
    • 23
  • a

    andylamax

    09/10/2021, 11:02 PM
    Hello there, Is it possible to export a react library as a js file that is not bundled with react? Coz we have the following problem Problem Hooks exported in our library don't work coz we have two instances or react (even if they are of the same version), So they fail with invalid hook call Desire Is it possible to declare react as a
    peerDependency
    and avoid it being bundled in the final build? That way the it will be bundled with the consumer's version of react? If this is not possible now, is it possible in the future (near or far)?
    t
    b
    • 3
    • 27
  • c

    calrissian

    09/12/2021, 9:36 PM
    Does anyone have any experience using react-boostrap in kotlin react app? I am thinking about using it but wanted to know if other were having issues with it
    n
    • 2
    • 4
  • n

    Nikola Milovic

    09/16/2021, 11:48 AM
    How can I render children in functional component with PropsWithChildren?, it doesnt seem to work with single children
    val MainScreen = fc<MainProps> { props ->
    ...
        sidebar { // has props with children
            when (child) { // this causes crash
                is Main.Child.Chat ->  p{attrs.text("heloooo test")}
                else -> p{attrs.text("heloooo error")}
            }
        }
    }
    
    external interface SidebarProps : PropsWithChildren {
    }
    
    val sidebar = fc<SidebarProps> { props ->
        props.children?.forEach {
                        child(it)
                    }
    }
    t
    c
    • 3
    • 4
  • c

    CLOVIS

    09/17/2021, 9:08 AM
    How do you pass children props to a class component in Kotlin React? Currently, I'm doing:
    child(MyClassComponent::class) {
      child(SomeFunctionalComponent)
    }
    then, in MyClassComponent.render:
    if (...) {
      props.children()
    }
    This works fine with 
    run
    , but fails with `browserProductionWebpack`:
    TypeError: _.render is not a function
    The commit with the full code (1 class component + its call), the version details. Originally posted in #javascript (here) but I was redirected here.
    t
    a
    • 3
    • 7
  • n

    nordiauwu

    09/21/2021, 3:23 PM
    Any chance for next.js support?
    a
    • 2
    • 2
  • p

    Pitel

    09/22/2021, 8:13 AM
    How smart/dumb idea is is to pass the
    StateInstance
    delegate in
    Props
    ? 🤔 So then child components could easily change state of parent component.
    t
    • 2
    • 5
  • n

    Nicodemus Ojwee

    09/23/2021, 6:47 AM
    How can i achieve something like this for a functional component in Kotlin react. Below is a code snippet from a class component written in Javascript. If you notice the code below updates the state and after something like a callback runs after. Basically what i want to achieve is to "Do something after state is updated" in a functional component.
    this.setState(state => ({
          ...state,
          stack: [...state.stack, state.sceneConfig[sceneName]],
        }), () => {
          // Do something here
        });
    t
    • 2
    • 2
  • n

    Nikola Milovic

    09/27/2021, 9:51 AM
    How can I pass a fc to other fc's props? My use case is that I want to pass another component alongside the children I am already passing into my functional component
    val chatSidebar = fc<ChatProps> { props -> // the fc that I want to pass 
    -----
    external interface SidebarProps : PropsWithChildren {
        var sidebarContent: FunctionComponent<Props> // want to pass it here
    }
    
    val sidebar = fc<SidebarProps> { props ->
       div { props.sidebarContent } // somehow do something like this
       props.children() //already using children for the main content
    This is how I want to use the sidebar
    sidebar {
            when (child) {
                is Main.Child.Chat -> {
                    attrs.sidebarContent = chatSidebar{} // add the corresponding content to the props alongside the main content
                    chat { attrs.component = child.component} // the child/ main content
    t
    • 2
    • 10
  • p

    Pitel

    10/04/2021, 12:52 PM
    What's the use case of
    PropsWithChildren
    ? Will the element(s) added there be automaticaly rendered? And what the difference with
    ReactNode.unaryPlus()
    in
    RBuilder
    ?
    t
    • 2
    • 2
  • n

    Nikola Milovic

    10/06/2021, 3:54 PM
    How to get onSubmit to work? Need this for
    react-hook-form
    wrapper
    form {
        attrs.onSubmitFunction = {
            console.log("Submit")
        }
        attrs.onSubmit = {
            console.log("Submit")
        }
    
        input(classes = defaultButtonStyle, type = InputType.submit) {
        }
    }
    Tried it with intput of type submit and with button of type submit, both refresh the page and nothing gets logged in the console. (Prevent default for button did work for preventing the refresh but it didn't log anything)
    t
    • 2
    • 1
  • n

    Nikola Milovic

    10/09/2021, 8:40 AM
    Why isn't this a valid js syntax? Any way around it without having to manually type it out
    fun getDefaultValuesFromProfile(profile: ProfileModel): dynamic {
        val d : dynamic = js("{ defaultValues : {...profile}}")
        return d
    }
    Which should be totally valid in ts (javascript)
    function test(profile: IProfile) {
      const test = { defaultValues: { ...profile } };
    }
    c
    t
    • 3
    • 7
  • p

    Pitel

    10/18/2021, 2:16 PM
    console.log(props.text.language?.id)
    
    val updateText = { newText: String ->
        console.log("updateText ${props.text.language?.id}")
        props.update(props.text.copy(body = newText))
    }
    
    val cm = useCodeMirror(jsObject {
        console.log("jsObject ${props.text.language?.id}")
        container = editor.current
        basicSetup = false
        extensions = arrayOf(
            StreamLanguage.define(mai),
            defaultHighlightStyle.fallback as Any
        )
        onChange = { text, _ ->
            console.log("onChange ${props.text.language?.id}")
            updateText(text)
        }
        height = "300px"
        value = props.text.body ?: ""
    })
    This is in the body of functional component. When run the first time, it looks ok, all logs shows language id
    1
    . But, when I pass new props, something weird happens:
    2
    jsObject 2
    onChange 1
    updateText 1
    Any idea why the
    onChange
    and
    updateText
    keeps the old value?!
    (The source of `useCodeMirror`: https://github.com/uiwjs/react-codemirror/blob/master/src/useCodeMirror.ts)
    t
    c
    • 3
    • 10
  • p

    Pitel

    10/29/2021, 8:43 AM
    How can i re-set values of context?
    SnackContext.Provider {
        attrs.value.showError = { errorSnack = true}
    This fails with
    Uncaught TypeError: Cannot set properties of undefined (setting 'showError')
    .
    t
    • 2
    • 4
  • m

    Mihai Voicescu

    11/11/2021, 2:47 PM
    Although this is a getter the value returned by it seems to always be the initial value in the scope of the closure
    var chats by useState(listOf<String>("first"))
    
        useEffectOnce {
            GlobalScope.launch {
                client.rtmStream().collect {
                    val current = chats // always initial value
                    println(current)
                    chats = current + it.message
                }
            }
        }
    Am I doing something wrong?
    d
    t
    c
    • 4
    • 11
  • g

    gbaldeck

    11/17/2021, 3:18 AM
    sorry if this question has already been answered, but I'm using the Kotlin/Js inspection plugin and in the generated Kotlin/React project it is saying that the data class which extends state should be an external interface. The most up to date docs show it as a data class. Is the inspection plugin lagging behind the most up to date docs or should it really be an external interface?
    t
    • 2
    • 5
  • p

    Piotr Krzemiński

    11/17/2021, 7:56 AM
    Hi, would it be possible to add kotlin-mui to kotlin-wrappers-bom? CC @turansky
    ✅ 1
    t
    • 2
    • 4
  • t

    Toby

    11/20/2021, 9:42 AM
    What is the preferred way of setting the mui-theme to dark for my whole kotlin -react app ?
    t
    • 2
    • 1
  • n

    nordiauwu

    11/24/2021, 1:29 PM
    Is it possible to exclude the react itself from kotlin-react? (it will be available at runtime)
    t
    • 2
    • 6
Powered by Linen
Title
n

nordiauwu

11/24/2021, 1:29 PM
Is it possible to exclude the react itself from kotlin-react? (it will be available at runtime)
t

turansky

11/24/2021, 1:58 PM
Webpack externals?
n

nordiauwu

11/24/2021, 5:04 PM
@turansky is there a working example?
t

turansky

11/24/2021, 5:53 PM
https://webpack.js.org/configuration/externals/
Only documentation
n

nordiauwu

11/24/2021, 6:12 PM
Well, I tried it but produced js still contains react
Solution:
config.externals = {
    'react': 'React',
    'react-dom': 'ReactDOM'
}
👍 2
View count: 8