https://kotlinlang.org logo
Docs
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
javascript
  • a

    Alex Edwards

    11/01/2021, 2:15 PM
    I’ve found myself using this pattern quite a lot, is there a better way (options is
    Deferred<Map<String, String>
    ?
    options.asPromise().then { // get a value from the options map }.asDeferred()
    p
    2 replies · 2 participants
  • g

    Greg Steckman

    11/01/2021, 7:03 PM
    I've got a build where the compileDevelopmentExecutableKotlinJs step can take a few minutes to complete. It sometimes happens on even very simple/minimal projects. Can anyone offer any suggestions for places I might look (e.g. logs) to determine what is the cause?
    t
    5 replies · 2 participants
  • a

    Alex Edwards

    11/01/2021, 9:51 PM
    Can anyone provide any insight on what causes this issue, I’m trying to build a project with IR
    > Task :idmapi-entrypoints:compileProductionExecutableKotlinJs FAILED
    e: java.lang.IllegalStateException: Not found Idx for private com.mypackage/|null[0]:40
            at org.jetbrains.kotlin.backend.common.serialization.IrFileDeserializer.loadTopLevelDeclarationProto(IrFileDeserializer.kt:48)
            at org.jetbrains.kotlin.backend.common.serialization.IrFileDeserializer.deserializeDeclaration(IrFileDeserializer.kt:39)
            at org.jetbrains.kotlin.backend.common.serialization.FileDeserializationState.deserializeAllFileReachableTopLevel(IrFileDeserializer.kt:139)
            at org.jetbrains.kotlin.backend.common.serialization.ModuleDeserializationState.deserializeReachableDeclarations(BasicIrModuleDeserializer.kt:172)
            at org.jetbrains.kotlin.backend.common.serialization.BasicIrModuleDeserializer.deserializeReachableDeclarations(BasicIrModuleDeserializer.kt:148)
    com.mypackage
    is another of my projects that this project depends on i have also compiled it with
    js(IR)
    but the issue could be that i’m still missing something there but its unclear from this error
    t
    a
    11 replies · 3 participants
  • v

    vngantk

    11/02/2021, 2:14 AM
    I am writing unit tests for my Kotlin client-side javascript code. The client code needs the support of a server which is also written in Kotlin in the same multiplatform Kotlin project. How can I start the server automatically when the unit tests start?
    e
    v
    2 replies · 3 participants
  • c

    Chukwukammadu Anizoba

    11/02/2021, 4:36 PM
    Hey guys, any idea how to set environment variables (.env) in a Kotlin JS node project? I've tried adding a .env file at the root of the project, but the server code is not picking up the variables from
    process.env
    . Cheers!
    a
    7 replies · 2 participants
  • a

    Alex Edwards

    11/02/2021, 4:41 PM
    Where should I be looking for the
    package.json
    file for a project with
    binaries.executable()
    ? i’ve looked at the file in
    myproject/build/tmp/jsPublicPackageJson
    and the one in
    build/js/packages/myproject
    and they are both missing packages from the dependency section that the generated js file has as
    require.
    If i go and look at the projects that pull in these dependencies directly their
    package.json
    files look as i would expect them to. This seems essentially the same as https://youtrack.jetbrains.com/issue/KT-45789
    b
    s
    +1
    23 replies · 4 participants
  • g

    Goregius

    11/02/2021, 5:53 PM
    I'm trying to type a default external class from the "values.js" npm module and it always responds with:
    Uncaught TypeError: Values_0 is not a constructor
    . The original code can be seen here: https://github.com/noeldelgado/values.js/blob/master/src/index.js. I've used this in the kt file:
    @file:JsModule("values.js")
    @file:JsNonModule
    
    @JsName("default")
    external class Values(color: String = definedExternally, type: String = definedExternally, weight: Int = definedExternally)
    Is this a problem with the module itself or how I'm defining the kotlin class?
    t
    6 replies · 2 participants
  • a

    Ayfri

    11/02/2021, 7:34 PM
    Hi, I was trying to update my project to Kotlin 1.5.31 (it was on 1.5.30) but now when I try to launch it I have this error message (see discussion)
    r
    2 replies · 2 participants
  • s

    Susmitha Gudapati

    11/03/2021, 12:47 PM
    Hi, I have a typescript application. I want to create a Kotlin based application but on the same ts contracts/states. Is there a way or a package that converts ts states to Kotlin classes. I've tried the Dukat library but it produces interfaces instead of classes and there are concerns with nested state objects as well.
    g
    1 reply · 2 participants
  • a

    Ayfri

    11/03/2021, 3:51 PM
    Hi, I have a project where I re-typed an entire TypeScript library to Kotlin/JS, but it's not executing the side-effects, like this :
    import {Something} from './file';
    import {Else} from './other';
    
    Something.execute(Else.thing);
    
    export {Something};
    In my case the code
    Something.execute(Else.thing)
    will not be executed, and so it's making the library not working unless I execute this code by hand in Kotlin, is there a way to fix this ?
    g
    b
    8 replies · 3 participants
  • a

    Ayfri

    11/03/2021, 4:53 PM
    The PIXI.js library working in Kotlin with full typings ^^
    👍 3
    :kotlin-intensifies: 8
    1 reply · 1 participant
  • e

    Etienne

    11/03/2021, 8:17 PM
    Is it possible to package
    resources
    inside a Kotlin/JS library, making them accessible to dependents? I'm not having much luck finding docs on the subject.
    b
    t
    15 replies · 3 participants
  • p

    Piotr Krzemiński

    11/04/2021, 7:23 AM
    What's your approach to unit-testing React components in Kotlin/JS? I found this https://github.com/mysticfall/Kotlin-react-test but it's pretty new - I'm wondering if there are any well-established practices. My goal is to take a component that possibly uses other components under the hood, and both be able to test it by verifying that it calls underlying components correctly, and assert on complete DOM.
    t
    t
    11 replies · 3 participants
  • e

    Eugen Martynov

    11/04/2021, 7:27 AM
    Hi people, I work on KMP project. And unit tests are failing for JS version with similar error
    AssertionError: Expected <1>, actual <1> is not same.
    	at Object.captureStack(/tmp/_karma_webpack_16032/commons.js:100023)
    	at AssertionError.constructor(/tmp/_karma_webpack_16032/commons.js:100325)
    	at <global>.new AssertionError(/tmp/_karma_webpack_16032/commons.js:100522)
    	at DefaultJsAsserter.assertTrue(/tmp/_karma_webpack_16032/commons.js:61035)
    	at DefaultJsAsserter.Asserter.assertSame(/tmp/_karma_webpack_16032/commons.js:60849)
    	at DefaultJsAsserter.assertSame(/tmp/_karma_webpack_16032/commons.js:61016)
    	at <global>.assertSame(/tmp/_karma_webpack_16032/commons.js:60213)
    	at com.badoo.reaktive.completable.RetryTest.predicate_receives_valid_counter_WHEN_upstream_produces_error(/tmp/_karma_webpack_16032/commons.js:3616)
    	at <global>.<unknown>(/tmp/_karma_webpack_16032/commons.js:30474)
    	at Context.<anonymous>(/tmp/_karma_webpack_16032/commons.js:60011)
    I assume there is wrong equals is used. However, I’m not JS developer so don’t have any clue where to look to unblock me. The same tests are not failing when I run them in IDE.
    p
    a
    +1
    31 replies · 4 participants
  • p

    Paul Idstein

    11/05/2021, 7:52 AM
    Hi, we are trying currently to migrate a Kotlin multiplatform project to Web. For that we plan to cross-compile all our native dependencies via emscripten to WebAssembly (that works so far pretty well). Bundling works pretty well using resources for Module JS + WASM files. However, as required by many WASM engines, we utilize asynchronous compilation (https://github.com/emscripten-core/emscripten/blob/main/src/settings.js#L1306). Can we somehow tell Kotlin/JS to resolve functions async?
    @file:JsModule("./wasm-js-module.js")
    @file:JsNonModule
    package pkg.native.wasm.library
    //typealias WasmPointer = Int
    @JsName("_some_simd_function")
    external fun fast_simd_calculus(input: WasmPointer, output: WasmPointer, size: Int)
    The generated code now looks like the following and yields of course an
    undefined
    method because the module is a
    Promise
    object
    (function (root, factory) {
      if (typeof define === 'function' && define.amd)
        define(['exports', './wasm-js-module.js'], factory);
      else if (typeof exports === 'object')
        factory(module.exports, require('./wasm-js-module.js'));
      else {
        if (typeof this['./wasm-js-module.js'] === 'undefined') {
          throw new Error("Error loading module 'pkg.native.wasm.library'....");
        }root['pkg'] = factory(typeof this['pkg'] === 'undefined' ? {} : this['pkg'], this['./wasm-js-module.js']);
      }
    }(this, function (_, $module$__wasm_js_module_js) {
      var fast_simd_calculus = $module$__wasm_js_module_js._some_simd_function;
    b
    9 replies · 2 participants
  • d

    Daniel Buřval

    11/05/2021, 11:01 AM
    HI i simply need to go to link which i provide (lets say /articles/myfavarticle). I am using hash router (reac-dom-router). So when i click on button element i want to redirect to that page. How should i do this ?
    :not-kotlin: 1
    ✅ 1
    1 reply · 1 participant
  • m

    Mahdi Shahpuri

    11/08/2021, 7:43 AM
    Hi is there any job in programming
    t
    1 reply · 2 participants
  • r

    Robert Munro

    11/08/2021, 9:56 PM
    hi I have just upgraded from kotlin 1.5.0 -> 1.5.31 and have hit an error with webpack config in a kotlinJS module - I'm hoping someone might have seen before -
    Cant resolve 'crypto' in DCE
    - it looks like i should just have to add some webpack config but i am unsure how to do it. The error is in the thread.
    BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
    This is no longer the case. Verify if you need this module and configure a polyfill for it.
    t
    a
    18 replies · 3 participants
  • a

    andylamax

    11/08/2021, 11:47 PM
    Is there an equivalent of
    @JvmSynthetic
    for
    kotlin/js
    ? Something like
    @JsSynthetic
    ? Reasons are almost similar to
    @JvmSynthetic
    for
    kotlin/jvm
    , don't need it to be callable form
    typescript/javascript
    b
    g
    +1
    9 replies · 4 participants
  • d

    Dave

    11/09/2021, 12:47 PM
    The generated Javascript code for Kotlin classes, sometimes creates an
    Object.defineProperty(<Class>.prototype, <property>)...
    statement(s), and sometimes not. Does anyone know the rules for when it is generated and when not, I am trying use some kotlin classes from JS code and sometimes I have access to the defined property, sometimes it is simply not defined ??
    1 reply · 1 participant
  • a

    ankushg

    11/09/2021, 6:57 PM
    Is it possible to get sourcemaps to use absolute paths instead of relative paths? When developing locally, we use
    yarn link
    a lot, and end up with mismatches between the generated sourcemap's relative path and where the code actually is. This can be annoying because it breaks in-browser debugging. Things would be easier for us if we could just use absolute paths instead. I've tried setting
    freeCompilerArgs += listOf(
                "-source-map-base-dirs", "/",
                "-source-map-prefix", "/"
            )
    but that doesn't seem to work.
    3 replies · 1 participant
  • t

    Tomasz Krakowiak

    11/11/2021, 6:26 AM
    Just an idea - It would be nice if DCE could output what gets included in output binary, why and what gets eliminated or inlined. I have hard time understanding why I get such a bit binary output for some small project. Maybe I have some unnecessary code dependency, that's cascading into whole lot of more code.
    e
    b
    5 replies · 3 participants
  • m

    Mihai Voicescu

    11/11/2021, 9:02 AM
    Webpack development server does not seem to work (with only the Idea new react project wizard and webpack version 4) Any ideas why?
    Waiting for changes to input files of tasks... (ctrl-d to exit)
    ⚠ 「wdm」: Hash: 4767918b5ca4297d4a2b
    Version: webpack 4.46.0
    Time: 6223ms
    Built at: 11/11/2021 9:59:04 AM
                Asset      Size  Chunks             Chunk Names
    remote-app-web.js  6.05 MiB    main  [emitted]  main
    Entrypoint main = remote-app-web.js
    [0] multi (webpack)-dev-server/client?<http://localhost:8080> ./kotlin/remote-app-web.js 40 bytes {main} [built]
    [../../node_modules/process/browser.js] /Users/mihaivo/IdeaProjects/remote-app-web/build/js/node_modules/process/browser.js 5.29 KiB {main} [built]
    [../../node_modules/react-dom/index.js] /Users/mihaivo/IdeaProjects/remote-app-web/build/js/node_modules/react-dom/index.js 1.33 KiB {main} [built]
    [../../node_modules/react/index.js] /Users/mihaivo/IdeaProjects/remote-app-web/build/js/node_modules/react/index.js 190 bytes {main} [built]
    [../../node_modules/styled-components/dist/styled-components.browser.esm.js] /Users/mihaivo/IdeaProjects/remote-app-web/build/js/node_modules/styled-components/dist/styled-components.browser.esm.js 26.3 KiB {main} [built]
    [../../node_modules/webpack-dev-server/client/index.js?<http://localhost:8080>] (webpack)-dev-server/client?<http://localhost:8080> 4.29 KiB {main} [built]
    [../../node_modules/webpack-dev-server/client/overlay.js] (webpack)-dev-server/client/overlay.js 3.51 KiB {main} [built]
    [../../node_modules/webpack-dev-server/client/socket.js] (webpack)-dev-server/client/socket.js 1.53 KiB {main} [built]
    [../../node_modules/webpack-dev-server/client/utils/createSocketUrl.js] (webpack)-dev-server/client/utils/createSocketUrl.js 2.91 KiB {main} [built]
    [../../node_modules/webpack-dev-server/client/utils/log.js] (webpack)-dev-server/client/utils/log.js 964 bytes {main} [built]
    [../../node_modules/webpack-dev-server/client/utils/reloadApp.js] (webpack)-dev-server/client/utils/reloadApp.js 1.59 KiB {main} [built]
    [../../node_modules/webpack-dev-server/client/utils/sendMessage.js] (webpack)-dev-server/client/utils/sendMessage.js 402 bytes {main} [built]
    [../../node_modules/webpack-dev-server/node_modules/strip-ansi/index.js] (webpack)-dev-server/node_modules/strip-ansi/index.js 161 bytes {main} [built]
    [../../node_modules/webpack/hot sync ^\.\/log$] (webpack)/hot sync nonrecursive ^\.\/log$ 170 bytes {main} [built]
    [./kotlin/remote-app-web.js] 1.85 MiB {main} [built] [238 warnings]
        + 39 hidden modules
    ✅ 1
    1 reply · 1 participant
  • m

    Mihai Voicescu

    11/11/2021, 2:46 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?
    ✅ 1
    1 reply · 1 participant
  • g

    Grégory Lureau

    11/12/2021, 10:32 AM
    If I define a method to return an exception, the typescript exposes the actual implementation, like :
    buildIllegalArgumentException(msg: string): kotlin.IllegalArgumentException;
    But in VsCode it's handled as
    any
    , I suspect because the kotlin.XxxException are not exposed in the .d.ts. Is there an option to make them defined/accessible for typescript?
    t
    7 replies · 2 participants
  • w

    w_bianrytree

    11/13/2021, 9:32 AM
    Is it possible to export the Typescript classes without full package name from my Kotlin code? except declare those files in root package
    :plus-one: 5
    b
    t
    +2
    12 replies · 5 participants
  • m

    martmists

    11/14/2021, 7:35 PM
    How would I emulate a
    require
    in kotlin/js?
    b
    1 reply · 2 participants
  • c

    Cedrick Cooke

    11/14/2021, 8:55 PM
    Introducing
    IndexedDB
    bindings for Kotlin/JS: https://github.com/JuulLabs/indexeddb
    👍 2
    t
    6 replies · 2 participants
  • m

    martmists

    11/15/2021, 12:57 AM
    what would be the kjs equivalent of
    module.exports = MyThingHere
    I've been trying to figure out how to do this with gradle and kjs but I haven't been able to generate a js file that looks even close to doing that, in most cases it actually just adds the package as attribute
    t
    b
    12 replies · 3 participants
  • d

    Daniel Buřval

    11/15/2021, 9:39 AM
    Hi, I have react component
    class MetaInfoFacebook : RComponent<MetaInfoFacebookProps, RState>() {
        companion object {
            const val PROPERTY_KEY = "property"
            const val CONTENT_KEY = "content"
    
            const val URL_META_FACEBOOK_PROPERTY = "og:url"
            const val TYPE_META_FACEBOOK_PROPERTY = "og:type"
            const val TITLE_META_FACEBOOK_PROPERTY = "og:title"
            const val DESCRIPTION_META_FACEBOOK_PROPERTY = "og:description"
            const val IMAGE_META_FACEBOOK_PROPERTY = "og:image"
        }
    
        override fun RBuilder.render() {
            meta {
                attrs[PROPERTY_KEY] = URL_META_FACEBOOK_PROPERTY
                attrs[CONTENT_KEY] = props.metaInfoFacebook.url
            }
    
            meta {
                attrs[PROPERTY_KEY] = TYPE_META_FACEBOOK_PROPERTY
                attrs[CONTENT_KEY] = props.metaInfoFacebook.type
            }
    
            meta {
                attrs[PROPERTY_KEY] = TITLE_META_FACEBOOK_PROPERTY
                attrs[CONTENT_KEY] = props.metaInfoFacebook.title
            }
    
            meta {
                attrs[PROPERTY_KEY] = DESCRIPTION_META_FACEBOOK_PROPERTY
                attrs[CONTENT_KEY] = props.metaInfoFacebook.description
            }
    
            meta {
                attrs[PROPERTY_KEY] = IMAGE_META_FACEBOOK_PROPERTY
                attrs[CONTENT_KEY] = props.metaInfoFacebook.image
            }
        }
    }
    
    external interface MetaInfoFacebookProps : RProps {
        var metaInfoFacebook: MetaInfoFacebook
    }
    I want to get meta tags of a page and append this component to existing tags. Is this possible? By getting document.head container and using child(MetaInfoFacebook ::class){} i replace existing tags, which i dont want to
    t
    1 reply · 2 participants
Powered by Linen
Title
d

Daniel Buřval

11/15/2021, 9:39 AM
Hi, I have react component
class MetaInfoFacebook : RComponent<MetaInfoFacebookProps, RState>() {
    companion object {
        const val PROPERTY_KEY = "property"
        const val CONTENT_KEY = "content"

        const val URL_META_FACEBOOK_PROPERTY = "og:url"
        const val TYPE_META_FACEBOOK_PROPERTY = "og:type"
        const val TITLE_META_FACEBOOK_PROPERTY = "og:title"
        const val DESCRIPTION_META_FACEBOOK_PROPERTY = "og:description"
        const val IMAGE_META_FACEBOOK_PROPERTY = "og:image"
    }

    override fun RBuilder.render() {
        meta {
            attrs[PROPERTY_KEY] = URL_META_FACEBOOK_PROPERTY
            attrs[CONTENT_KEY] = props.metaInfoFacebook.url
        }

        meta {
            attrs[PROPERTY_KEY] = TYPE_META_FACEBOOK_PROPERTY
            attrs[CONTENT_KEY] = props.metaInfoFacebook.type
        }

        meta {
            attrs[PROPERTY_KEY] = TITLE_META_FACEBOOK_PROPERTY
            attrs[CONTENT_KEY] = props.metaInfoFacebook.title
        }

        meta {
            attrs[PROPERTY_KEY] = DESCRIPTION_META_FACEBOOK_PROPERTY
            attrs[CONTENT_KEY] = props.metaInfoFacebook.description
        }

        meta {
            attrs[PROPERTY_KEY] = IMAGE_META_FACEBOOK_PROPERTY
            attrs[CONTENT_KEY] = props.metaInfoFacebook.image
        }
    }
}

external interface MetaInfoFacebookProps : RProps {
    var metaInfoFacebook: MetaInfoFacebook
}
I want to get meta tags of a page and append this component to existing tags. Is this possible? By getting document.head container and using child(MetaInfoFacebook ::class){} i replace existing tags, which i dont want to
t

turansky

11/15/2021, 1:39 PM
It looks like effect responsibility
View count: 12